CoverageChecker.CommandLine 0.6.1

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global CoverageChecker.CommandLine --version 0.6.1
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local CoverageChecker.CommandLine --version 0.6.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CoverageChecker.CommandLine&version=0.6.1
                    
nuke :add-package CoverageChecker.CommandLine --version 0.6.1
                    

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.

This package has no dependencies.

Version Downloads Last Updated
0.9.0 530 2/15/2026
0.8.0 295 1/11/2026
0.7.0 878 10/4/2025
0.6.6 212 9/28/2025
0.6.5 165 11/24/2024
0.6.4 171 11/13/2024
0.6.3 165 11/10/2024
0.6.2 149 11/10/2024
0.6.1 162 10/25/2024
0.6.0 178 10/20/2024
0.5.1 182 9/29/2024
0.5.0 156 9/29/2024