Quantcast
Channel: JPHellemons
Viewing all articles
Browse latest Browse all 132

Code coverage .Net core unit testing

$
0
0

As you have noticed, you need Visual Studio Enterprise for live unit testing, or Jetbrains Rider, or some Visual Studio Code “hacks”. Here is a method to have coverage of .Net core with a global tool:

Daniel Palme has a global tool version of Report Generator. You should install it once with:

dotnet tool install -g dotnet-reportgenerator-globaltool

dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools

You can then run it with `reportgenerator` so after building I run:

dotnet test --filter FullyQualifiedName~UnitTests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*Test*]" /p:ExcludeByAttribute="GeneratedCodeAttribute"
reportgenerator "-reports:**\coverage.opencover.xml" "-targetdir:C:\Temp\Reports\" "-reporttypes:HTML"
Start-Process -FilePath "C:\Temp\Reports\index.htm"

Of course you can go to the project properties and add the three lines of powershell to a file in the root of your solution and add to the build events tab as post-build:

Powershell -File "$(SolutionDir)nameOfPowershellscript.ps1"

Good luck!


Viewing all articles
Browse latest Browse all 132

Trending Articles