Skip to content

Blog

Code Coverage made Easy: A Step-by-Step Guide for .NET 6

For .Net 4.8 it was enough to install Visual Studio Enterprise Edition on the build server and check the box for code coverage in the Testing task of Azure DevOps. The build agent then collected the coverage data and published it as part of your builds. Unfortunately, for .Net 6 this no longer works, and we need to go through a lot more steps.

There are a handful projects for code coverage that support .Net "core", but not every project is still under active development. Be careful when you select a coverage tool and make sure that there is still some activity going on.

How to Get Faster Test Tasks in Your Azure DevOps Pipeline

A side effect we noticed after the migration to .Net 6 was that the test task in Azure DevOps took a lot longer than before. The test execution itself did not change much, but the dotnet test task had much more overhead than vstest. As an example, the test task took 4m 48s, while the test execution only took 1m 34s – giving us an overhead of 3m 14s or roughly 75% of the total time:

The pipeline took a lot more time than the test run.

How to Replace Ninject Modules with a IServiceCollection for the ASP.Net DI Container

To my great surprise, I had to realise that the development of Ninject is hardly progressing anymore. I was a huge fan of Ninject and used it for 8 years without any problems. But without any meaningful progress over the last years, I doubt that Ninject is still a good choice for .Net 6 applications. Does it work in .Net 6+? Maybe, but the issues on GitHub do not give me confidence.

Therefore, we decided to minimise our risks and switch to the default dependency injection container in ASP.Net as part of our migration to .Net 6. Microsoft may stop developing that container as well, but at least it should be part of .Net 8.