This solution uses Coverlet for code coverage and generates reports via the .NET CLI.
Visual Studio Test Explorer is not used for coverage generation in this setup due to inconsistencies in coverage collection behavior. Instead, coverage is generated via the command line for consistent results across local development and CI.
Ensure the following are installed:
- .NET SDK 6+ / 7+ / 8+ (depending on the solution)
- ReportGenerator global tool
dotnet tool install -g dotnet-reportgenerator-globaltoolOr update it:
dotnet tool update -g dotnet-reportgenerator-globaltoolFrom the solution root directory, run:
dotnet test --settings ./coverlet.runsettingsThis will:
- Execute all tests in the solution
- Collect code coverage using Coverlet
- Generate
coverage.cobertura.xmloutput files (typically underTestResults/or project output folders)
After tests complete, generate a human-readable HTML report:
reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coveragereport" -reporttypes:HtmlThis will:
- Aggregate all
coverage.cobertura.xmlfiles in the solution - Generate an HTML report in the
coveragereport/directory
Open the generated report in a browser:
coveragereport/index.html
- Coverage is only generated when running tests via
dotnet testwith the provided runsettings file. - Running tests through Visual Studio Test Explorer will execute tests but will not generate coverage reports in this setup.
- Always run commands from the solution root to ensure correct relative paths.
# 1. Run tests + collect coverage
dotnet test --settings ./coverlet.runsettings
# 2. Generate HTML report
reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coveragereport" -reporttypes:Html
# 3. Open report (Windows)
start coveragereport/index.html