dotnet test --collect:"XPlat Code Coverage" /p:CoverletOutputFormat=cobertura
Running dotnet test --collect "Code Coverage"
at the solution level now automatically merges code coverage for all your test projects. See here for more information.
# These 2 commands do the same thing:
dotnet test --no-build --collect "Code Coverage;Format=cobertura"
dotnet-coverage collect -f cobertura -o report.cobertura.xml "dotnet test --no-build"
Instead of passing parameters to CLI command, you can use a .runsettings
file instead:
dotnet test -s local.runsettings
💡
local.runsettings
is for running tests locally whilecicd.runsettings
is for running tests using GitHub workflows.
Warning
💡 This currently only works with coverlet
. Attempting to use Microsoft.CodeCoverage
will silently fail.
-
Install Coverage Gutters if not already installed.
-
Make sure the setting
coverage-gutters.coverageFileNames
insettings.json
includes"coverage.cobertura.xml"
as shown below:"coverage-gutters.coverageFileNames": [ "lcov.info", "cov.xml", "coverage.xml", "jacoco.xml", "coverage.cobertura.xml" ]
-
From Command Palette, select Coverage Gutters: Display Coverage after you have run unit tests (see previous section).
When building for CI/CD, we want to keep package versions locked based on lock file(s). If you encounter NU1403
, try doing the following (source):
dotnet nuget locals all --clear
git clean -xfd
git rm **/packages.lock.json -f
dotnet restore