DEV Community

David Guida
David Guida

Posted on

Bad test coverage results? No worries!

Yesterday I stumbled upon an “interesting” bug in the code coverage tool. In case you’re generating it (and I strongly encourage you to), please make sure you’re satisfied with the results.

At work by policy we have to ensure at least 70% of test coverage. However in one of my projects I was getting way worse results, in some cases even 0%.

I’m pretty paranoid about testing, and when possible I tend to follow TDD along with the Test Pyramid.

Long story short, I found out that if you have long running tests (eg. single tests taking more than 10 seconds to complete) AND you’re using .NET Core, the dotnet test command might terminate its execution before the report files get written. This will lead to bad results, in some cases even 0% ( which happened to me).

But fear not! The solution is at hand and relatively easy to implement. Just follow the steps outlined here: https://github.com/tonerdo/coverlet/issues/573#issuecomment-536593477

In my case I managed to move from a very sad 25% to a shiny 78%. In one case I even got 90%!

Interesting enough, generating the coverage report directly from Visual Studio Enterprise leads to even better results.

For more details you can take a look here:

Oh and don’t forget that if you have NDepend, you can import the coverage results and have a very pretty report.

courtesy of NDepend

They also have an excellent tutorial on the website that will guide you through all the steps.

Top comments (0)