You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ability to fail tests if minimum coverage not met #160
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:
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.
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).
Activity
DanielGilOrtiz commentedon Oct 6, 2026
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-thresholdon 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-rateand fails the build. That step is also easy to get wrong: the empty report in #251 hasline-rate="1", so it passes. A built-in--coverage-threshold 80would 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.
Evangelink commentedon Oct 8, 2026
I am working on adding the feature at MTP level for milestone
2.6Evangelink commentedon Oct 9, 2026
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-toolspublic feed.fhnaseer feel free to close now (except if you prefer to wait for the release).