johnkary / phpunit-speedtrap

Reports on slow-running tests in your PHPUnit test suite
MIT License
782 stars 60 forks source link

New option stopOnSlow halts execution upon first slow test #82

Closed johnkary closed 3 years ago

johnkary commented 3 years ago

Alternate implementation for #64. Thanks @PeterDKC for proposing this idea.

Some test suites run for a long time. PHPUnit already supports command-line options for halting execution when different test result types are first encountered. This allows more quickly notifying developers about problems in the test suite.

This PR proposes a new SpeedTrap option stopOnSlow to stop execution upon the first slow test.

The option is controlled using phpunit.xml like other SpeedTrap options:

<phpunit bootstrap="vendor/autoload.php">
    <!-- ... other suite configuration here ... -->

    <listeners>
        <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
            <arguments>
                <array>
                    ...
                    <element key="stopOnSlow">
                        <boolean>false</boolean>
                    </element>
                </array>
            </arguments>
        </listener>
    </listeners>
</phpunit>

What does it look like when the test suite halts due to a slow test?

The slowness report displays with the single slow test, followed by PHPUnit's normal test runner report.

Screenshot 2021-02-28 11 06 36 png@2x