At my current company we are using Substrate for our developments, we have an automated setup with test and whatnot. We are now evaulating our options regarding code coverage.

We are thinking of a combination of cargo-tarpaulin with codecov since we use Github actions for our CI.

We were wondering though, what recommended setups are there, specially because although substrate code is based on Rust, the specific macro usage in some scenarios makes code coverage analysis a bit more complicated.

Our end goal is to mainly cover our own developed pallets, like so:

cargo tarpaulin
  --no-fail-fast \
  --workspace \
  --exclude-files node/* primitives/* rpc/* runtime/*

So in the end, my question is: What is the recommended approach for code coverage in Substrate?

1 Answer 1


What is the recommended approach for code coverage in Substrate?

TBH I don't think there is any. This topic is under-valued IMO.

I have used kcov with Tarpaulin for a Pallet project in the past and it works reasonably well.
You can see the GH actions file here.
It needs some manual tweaking for Rust integration tests, since kvoc only assumes unit tests and some other annoyances but in general it provides usable coverage info. Especially missing error paths. It also works together with Codecov.

There is one shortcoming in Substrate of which the TLDR is to not use thread locals in tests ever.
Just use parameter_types or storage instead.

  • Great, thanks for your answer!
    – DidacSF
    Commented Oct 27, 2022 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.