CoverageChecker 0.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CoverageChecker --version 0.6.0
                    
NuGet\Install-Package CoverageChecker -Version 0.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CoverageChecker" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoverageChecker" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="CoverageChecker" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CoverageChecker --version 0.6.0
                    
#r "nuget: CoverageChecker, 0.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CoverageChecker@0.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CoverageChecker&version=0.6.0
                    
Install as a Cake Addin
#tool nuget:?package=CoverageChecker&version=0.6.0
                    
Install as a Cake Tool

Coverage Checker

Build, Test and Publish

Allows for the checking of code coverage using the provided GitHub action or NuGet package.

GitHub Action

Usage

The code coverage must already have been generated and saved in a file. The action will then parse the coverage file and check the coverage. If desired, the action will fail if the coverage is below the specified threshold.

The action supports the following coverage file formats:

  • SonarQube
  • Cobertura
- name: Check coverage
  id: check-coverage
  uses: Thomas-Shephard/coverage-checker@v0.2.0
  with:
    format: 'Cobertura'
    directory: 'coverage'
    glob: '**/coverage.cobertura.xml'
    line-threshold: 80
    branch-threshold: 80
    fail-if-below-threshold: true

Inputs

Name Description Required Default
format The format of the coverage file. Options: SonarQube, Cobertura Yes
directory The directory containing the coverage file(s). No The current directory
glob-pattern The glob pattern to match the coverage file(s). Yes
line-threshold The line coverage threshold. No 80
branch-threshold The branch coverage threshold. No 80
fail-if-below-threshold Whether to fail the action if the coverage is below the threshold. No true
fail-if-no-files-found Whether to fail the action if no coverage files are found. No true

Outputs

Name Description
line-coverage The line coverage of the project.
branch-coverage The branch coverage of the project.

These outputs can be used in subsequent steps, as shown below:

- name: Use coverage results
  run: |
    echo "Line coverage ${{ steps.check-coverage.outputs.line-coverage }}"
    echo "Branch coverage ${{ steps.check-coverage.outputs.branch-coverage }}"

NuGet Package

Installation

Install the CoverageChecker NuGet package using the .NET CLI:

dotnet add package CoverageChecker

Features

Supported Coverage Formats

The following coverage formats are supported:

Coverage Analysis

The coverage analyser can be used to check the coverage of a project; both line and branch coverage are supported. Coverage can be calculated based on package, file, class, method, line, etc.

Code Example
using CoverageChecker;
using CoverageChecker.Results;

const CoverageFormat coverageFormat = CoverageFormat.Cobertura;
const string directory = @"file-directory";
const string globPattern = "*.xml";

CoverageAnalyser analyser = new(coverageFormat, directory, globPattern);
Coverage coverage = analyser.AnalyseCoverage();

if (coverage.Files.Count is 0) {
    Console.WriteLine("No coverage files found");
    return;
}

foreach (FileCoverage fileCoverage in coverage.Files) {
    Console.WriteLine($"Package {fileCoverage.PackageName ?? ""}: File={fileCoverage.Path} Lines={fileCoverage.Lines.Count}");

    foreach (IGrouping<string?, LineCoverage> classCoverage in fileCoverage.Lines.GroupBy(line => line.ClassName)) {
        Console.WriteLine($"\tClass {classCoverage.Key ?? ""}");

        foreach (LineCoverage line in classCoverage.OrderBy(line => line.LineNumber)) {
            Console.WriteLine(line.Branches is null
                                  ? $"\t\tLine {line.LineNumber}: Covered={(line.IsCovered ? "Yes" : "No")}"
                                  : $"\t\tLine {line.LineNumber}: Covered={(line.IsCovered ? "Yes" : "No")}, Branches=({line.CoveredBranches}/{line.Branches})");
        }
    }
}

Console.WriteLine($"Total line coverage: {coverage.CalculateOverallCoverage():P1}");
Console.WriteLine($"Total branch coverage: {coverage.CalculateOverallCoverage(CoverageType.Branch):P1}");

Contributions

Contributions are welcome! Read the contributing guide to get started.

License

This project is licensed under the MIT License. See the LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.0 124 2/15/2026
0.8.0 118 1/11/2026
0.7.0 186 10/4/2025
0.6.6 172 9/28/2025
0.6.5 171 11/24/2024
0.6.4 168 11/13/2024
0.6.3 172 11/10/2024
0.6.2 163 11/10/2024
0.6.1 168 10/25/2024
0.6.0 180 10/20/2024
0.5.1 164 9/29/2024
0.5.0 168 9/29/2024
0.4.0 187 9/7/2024
0.3.1 390 7/12/2024
0.3.0 186 7/7/2024
0.2.2 172 6/14/2024
0.2.1 185 6/13/2024
0.2.0 170 6/9/2024
0.1.0 178 6/8/2024