Posted by Anuraj on Friday, August 3, 2018 Reading time :1 minute
This post is about how to measure .net core code coverage with Jetbrains dotCover. dotCover is a .NET Unit Test Runner and Code Coverage Tool.
First you need to install the dotCover.CommandLineTools package from nuget. Instead of referencing it in the project file, you need to modify the project file and include it as CLI tool. You can do it like this.
Next you need to restore the package references, you can do it by running
dotnet restore command. Once it is done, you can run the command
dotnet dotcover test, which will instrument the assemblies, run the unit tests and generate reports for code coverage.
You can get the command line tool help using
dotnet dotcover help command. In this particular example, I am running the tool with following arguments, for analyzing and calculating code coverage for a particular assembly, and I am using report format as HTML, so that I can have a look into it and can be shared to my stake holders or clients if required. It will be available in the execution directory.
If you are using TeamCity for continuous integration, there is direct option to fail the build if the code coverage is not enough. If you are using any other CI tool you can configure MS Build step to check the condition and mark the build as failed. Similar to ReSharper command line tools, dotCover command line is also free, so you don’t require Visual Studio Enterprise edition to measure code coverage.
Happy Programming :)