Skip to content

Ability to fail tests if minimum coverage not met #160

Closed

Description

Summary

Add the ability to fail the build if a minimum level of coverage is not achieved.

Background and Motivation

Playing around with an existing xunit v3 project to have it use Microsoft Testing Platform, and as part of that work to maintain code coverage I've needed to drop coverlet to instead use the coverage extension.

A missing feature by comparison compared to coverlet is the ability to fail the build if a minimum code threshold isn't met.

In coverlet this is achieved via an MSBuild property in one of two formats:

<!-- Fail if line, method or branch coverage is less than 70 -->
<Threshold>70</Threshold>
<!-- Fail if line, method or branch coverage is less than 70, 75 and 50 respectively -->
<Threshold>70,75,50</Threshold>

Proposed Feature

Add a new feature that can be controlled through the command-line, for example:

--coverage-threshold 75

This could then be customised on a per-test-project basis:

<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --coverage-threshold 42</TestingPlatformCommandLineArguments>

Alternative Designs

None proposed.

Activity

  1. DanielGilOrtiz commented on Oct 6, 2026

    @DanielGilOrtiz

    Since this was opened, MTP 2.4 added the platform side of this feature (microsoft/testfx#9896, RFC 019): a collector can publish threshold results, and a failed threshold makes the run exit with code 14. This extension already uses that model for the summary added in #233 (18.11.2), and coverlet.MTP 10.1.0 already ships --coverlet-threshold on top of it (coverlet-coverage/coverlet#2019). The missing piece is a threshold option here.

    Our use case: an Azure Pipelines PR policy requiring 80% line coverage. Today each pipeline needs an extra step that parses the Cobertura line-rate and fails the build. That step is also easy to get wrong: the empty report in #251 has line-rate="1", so it passes. A built-in --coverage-threshold 80 would replace the step and could handle no-data explicitly.

    fhnaseer is this on the roadmap now that the platform support exists? cc Amaury Levé (@Evangelink), as your RFC 019 notes the collector-side option is tracked separately.

  2. Evangelink commented on Oct 8, 2026

    @Evangelink
    Member

    I am working on adding the feature at MTP level for milestone 2.6

  3. Evangelink commented on Oct 9, 2026

    @Evangelink
    Member

    I have so far only implemented branch/line coverage thresholds. PR was merged so 2.6/4.6 previews have the content if you want to start dogfooding from test-tools public feed.

    fhnaseer feel free to close now (except if you prefer to wait for the release).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions