Getting coverage of unit tests in a .NET Core project
Important: .NET Core 1.1 and earlier is not supported.
If you want to perform coverage analysis of unit tests in a .NET Core project, you have the following options:
- Use dotCover integrated in Visual Studio.
- Use dotCover integrated in JetBrains Rider.
- Use dotCover console runner.
There’s a separate command for getting coverage in .NET Core projects: cover-dotnet or just dotnet.
For example, we want to get coverage of tests in some project. Typically, all we need is open the project folder and run:
dotCover.exe dotnet --output=myRep.html --reportType=HTML -- test
Notes: - In this example, we run the command from the project folder. Alternatively, you can specify the full path to the project after test.
- --output=myRep.html --reportType=HTML tells dotCover to generate a coverage report in the HTML format.
- -- test at the end is an argument passed to dotnet. Actually you can replace it with --targetArguments=”test” but it is way longer.
- If you have more than one dotnet installations, you must use cover command and specify a path to the desired installation in the --targetExecutable argument.
- Use the dotCover .NET Core CLI per-project extension. For more info about CLI extensions, refer to MSDN.
Please sign in to leave a comment.