8. Risky Tests
Tests that are considered risky do not contribute to code coverage.
By default, PHPUnit is strict about tests that do not test anything: tests that do not perform assertions and do not configure expectations on mock objects.
This check can be disabled by using the option on the command-line or by setting beStrictAboutTestsThatDoNotTestAnything="false"
in PHPUnit’s .
A test that is attributed with PHPUnit\Framework\Attributes\CoversClass
or PHPUnit\Framework\Attributes\CoversFunction
(or annotated with ) and that executes code which is not specified using PHPUnit\Framework\Attributes\CoversClass
, PHPUnit\Framework\Attributes\CoversFunction
, PHPUnit\Framework\Attributes\UsesClass
, or (or using the @covers or annotations) will be considered risky when this check is enabled.
Furthermore, by setting requireCoverageMetadata="true"
in PHPUnit’s XML configuration file, a test can be considered risky when it does not have code coverage metadata.
PHPUnit can be strict about output during tests. This check can be enabled by using the --disallow-test-output
option on the command-line or by setting beStrictAboutOutputDuringTests="true"
in PHPUnit’s .
PHPUnit can enforce a time limit for the execution of a test when the pcntl
extension is available. The enforcing of this time limit can be enabled by using the --enforce-time-limit
option on the or by setting enforceTimeLimit="true"
in PHPUnit’s XML configuration file.
A test that is attributed with PHPUnit\Framework\Attributes\Large
(or annotated with ) will be considered risky when it takes longer than 60 seconds to run. This timeout is configurable via the timeoutForLargeTests
attribute in the .
A test that is attributed with PHPUnit\Framework\Attributes\Medium
(or annotated with @medium
) will be considered risky when it takes longer than 10 seconds to run. This timeout is configurable via the timeoutForMediumTests
attribute in the XML configuration file.
PHPUnit can be strict about tests that manipulate global state. This check can be enabled by using the --strict-global-state
option on the command-line or by setting in PHPUnit’s .