Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failure during setup swallows test outcome #5493

Closed
Jean85 opened this issue Aug 31, 2023 · 1 comment
Closed

Assertion failure during setup swallows test outcome #5493

Jean85 opened this issue Aug 31, 2023 · 1 comment
Labels
feature/assertion Issues related to assertions and expectations feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@Jean85
Copy link
Contributor

Jean85 commented Aug 31, 2023

Q A
PHPUnit version 10.3.2
PHP version 8.2.8
Installation Method Composer

Summary

Assertion failures during setUp lead to no test outcome, nor any indication of failure, only "No tests executed".

Current behavior

$ vendor/bin/phpunit
PHPUnit 10.3.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.8
Configuration: /var/www/pagamenti/phpunit.xml.dist

No tests executed!

How to reproduce

class FooTest extends TestCase
{
    public function setUp(): void
    {
        $this->assertTrue(false);
    }

    public function test(): void
    {
        $this->assertTrue(true);
    }
}

This is a partial redacted log:

# ...
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (101 tests)
Test Suite Started (/var/www/***/phpunit.xml.dist, 101 tests)
Test Suite Started (integration, 101 tests)
Test Suite Started (Tests\FooTest, 1 test)
Test Preparation Started (Tests\FooTest::testBar)
Assertion Succeeded (Constraint: is not null, Value: Symfony\Component\HttpClient\TraceableHttpClient Object #3202 (
    # ...
))
Assertion Succeeded (Constraint: is not null, Value: Notifiche\Config Object #3179 (
    # ...
))
Assertion Failed (Constraint: is equal to 200, Value: 500)
Before Test Method Called (Tests\FooTest::setUp)
Before Test Method Finished:
- Tests\FooTest::setUp
Test Failed (Tests\FooTest::testBar)
Failed asserting that 500 matches expected 200.
After Test Method Called (Tests\FooTest::tearDown)
After Test Method Called (Tests\FooTest::tearDownProphecy)
After Test Method Finished:
- Tests\FooTest::tearDown
- Tests\FooTest::tearDownProphecy
Test Suite Finished (Tests\FooTest, 1 test)
# ...
Test Suite Finished (integration, 101 tests)
Test Suite Finished (/var/www/pagamenti/phpunit.xml.dist, 101 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)

Expected behavior

Any indication on the failure.

@Jean85 Jean85 added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Aug 31, 2023
@sebastianbergmann sebastianbergmann added feature/test-runner CLI test runner feature/assertion Issues related to assertions and expectations labels Aug 31, 2023
@sebastianbergmann
Copy link
Owner

This breaks for me in a different way ;-)

Issue5493Test.php

<?php declare(strict_types=1);
namespace PHPUnit\TestFixture\Issue5493;

use PHPUnit\Framework\TestCase;

final class Issue5493Test extends TestCase
{
    protected function setUp(): void
    {
        $this->assertTrue(false);
    }

    public function testOne(): void
    {
        $this->assertTrue(true);
    }
}
$ phpunit --do-not-cache-result --no-configuration Issue5493Test.php
PHPUnit 10.3.4-10-g3bc96df835 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.10

There was 1 failure:

1) PHPUnit\TestFixture\Issue5493\Issue5493Test::testOne
Failed asserting that false is true.

/usr/local/src/phpunit/tests/end-to-end/regression/5493/Issue5493Test.php:11

No tests executed!

As you can see in the output above, I see the failure from the assertion in setUp(). But in the end the wrong No tests executed! statement is printed.

While this should be fixed, I would like to point out that assertions should not be used in a "before test method". These methods are only intended to be used to set up the test fixture. They should not be used to perform assertions.

sebastianbergmann added a commit that referenced this issue Sep 17, 2023
@sebastianbergmann sebastianbergmann changed the title Assertion failures during setup swallows test outcome. Assertion failures during setup swallows test outcome Sep 17, 2023
@sebastianbergmann sebastianbergmann changed the title Assertion failures during setup swallows test outcome Assertion failure during setup swallows test outcome Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

2 participants