Ever wanted to see test coverage of your solution?
0. add coverlet.collector nuget to test project
1. Install reporting tool:
0. add coverlet.collector nuget to test project
1. Install reporting tool:
dotnet tool install -g dotnet-reportgenerator-globaltool
2. Run tests and store results in a temp folder (you don't want those result file trashing your solution folder):
dotnet test --collect:"XPlat Code Coverage" -r $env:TEMP\CodeCoverage;
or if you want to exclude some files, just add runsettings.xml:
dotnet test --settings runsettings.xml -r $env:TEMP\CodeCoverage;
3. Generate report:
Test results will be stored in a folder with guid, so the tricky part here is to find the lastest created folder
Test results will be stored in a folder with guid, so the tricky part here is to find the lastest created folder
reportgenerator -reports:((gci $env:TEMP\CodeCoverage | sort CreationTime -desc | select -f 1).FullName +"\coverage.cobertura.xml") -targetdir:$env:TEMP\CodeCoverResult -reporttypes:Html;
4. Open it:
start $env:TEMP\CodeCoverResult\index.html Join all in one PowerShell file and enjoy one-click code coverage or use it on CI\CD
Comments
Post a Comment