Skip to content
Latchkey

PHPUnit "This test did not perform any assertions" (Risky)

PHPUnit marked a test "risky" because it ran without making a single assertion. With strict settings (or --fail-on-risky) in CI, a risky test is a hard failure even though the code under test did not error.

What this error means

CI fails with "This test did not perform any assertions" (an R/risky marker), often after enabling beStrictAboutTestsThatDoNotTestAnything. The test "ran" but asserted nothing - a silent no-op that strict mode promotes to a failure.

PHPUnit output
There was 1 risky test:

1) Tests\Unit\OrderTest::testTotalsAreCalculated
This test did not perform any assertions

/app/tests/Unit/OrderTest.php:18

Common causes

Test body has no assertion

The test exercises code but never calls an assert*/expect*. Strict mode flags it because a test that asserts nothing cannot actually fail on a regression.

Assertions live only in mocked expectations

A test relies solely on a mock expectation. Unless it is counted as an assertion (or you add expectNotToPerformAssertions()/assertTrue), PHPUnit sees zero assertions.

How to fix it

Add a real assertion

OrderTest.php
public function testTotalsAreCalculated(): void
{
    $order = new Order([10, 5]);
    $this->assertSame(15, $order->total());
}

Declare intentionally assertion-free tests

For a test whose only job is "this does not throw," mark it explicitly so strict mode is satisfied.

AppTest.php
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function testBootsWithoutError(): void
{
    new App();
}

How to prevent it

  • Keep beStrictAboutTestsThatDoNotTestAnything on to catch no-op tests.
  • Assert an observable outcome in every test.
  • Annotate the rare genuinely assertion-free test explicitly.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →