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
Option to mark test as risky when it does not contribute to code coverage #4501
When code coverage analysis is active then a test that is not annotated with @coversNothing and does not contribute to code coverage should be marked as risky.
This is done in order to prevent the test from being marked as risky because it does not assert anything and/or to create the false impression that a project has tests.
changed the title [-]Option to mark test as risky when it does not generate code coverage[/-][+]Option to mark test as risky when it does not contribute to code coverage[/+]on Apr 12, 2026
I will implement requireCoverageContribution (XML) and --require-coverage-contribution (CLI) for PHPUnit 13.2.
When code coverage analysis is active and this risky test check is enabled, PHPUnit will mark a test as risky when it does not execute any line of the code it is expected to cover.
This helps identify tests that create the false impression of being useful, for example:
This test declares that it covers Foo, passes because of its trivial assertion, and would not be flagged by the existing "did not perform any assertions" check. But it never actually executes any code in Foo, so it does not contribute to code coverage.
Tests annotated with #[CoversNothing] will not be affected by this new risky test check, as they explicitly declare that they are not expected to contribute to code coverage.
Activity
spriebsch commentedon Oct 30, 2020
Thanks for being my GitHub proxy, again ;-)
R4c00n commentedon Nov 2, 2020
Hi @sebastianbergmann and @spriebsch,
I think this is a nice idea! I would love to help and made a quick prove of concept.
Is this the place and way you thought of, or would you tackle this completely different? https://github.com/sebastianbergmann/phpunit/compare/master...R4c00n:risky-because-no-coverage?expand=1
As I said, this is just a quick POC. Still missing proper tests and configuration options and stuff.
[-]Option to mark test as risky when it does not generate code coverage[/-][+]Option to mark test as risky when it does not contribute to code coverage[/+]sebastianbergmann commentedon Apr 12, 2026
I will implement
requireCoverageContribution(XML) and--require-coverage-contribution(CLI) for PHPUnit 13.2.When code coverage analysis is active and this risky test check is enabled, PHPUnit will mark a test as risky when it does not execute any line of the code it is expected to cover.
This helps identify tests that create the false impression of being useful, for example:
This test declares that it covers
Foo, passes because of its trivial assertion, and would not be flagged by the existing "did not perform any assertions" check. But it never actually executes any code inFoo, so it does not contribute to code coverage.Tests annotated with
#[CoversNothing]will not be affected by this new risky test check, as they explicitly declare that they are not expected to contribute to code coverage.Document sebastianbergmann/phpunit#4501
Closes #4501
Document sebastianbergmann/phpunit#4501