keystone / phpunit-broom-wagon
Find slow tests within your PHPUnit test suite.
Requires
- php: >=5.6
- phpunit/phpunit: ^4.0|^5.0
This package is not auto-updated.
Last update: 2024-11-09 21:17:06 UTC
README
A PHPUnit test listener that reports on slow-running tests. Forked from johnkary/phpunit-speedtrap to allow more control over slow thresholds and support for PHPUnit 5.
Broom Wagon?
The broom wagon is the name given to the vehicle that follows a cycling road race "sweeping" up stragglers who are unable to make it to the finish of the race within the time permitted. As a cyclist it makes sense to me.
Installation
Install via Composer
composer require --dev keystone/phpunit-broom-wagon
Usage
Enable the listener by adding it to your phpunit.xml
configuration file.
<phpunit bootstrap="vendor/autoload.php"> <listeners> <listener class="Keystone\PHPUnit\BroomWagon\TestListener" /> </listeners> </phpunit>
Now run your test suite as normal. If tests take longer than the slow threshold (500ms by default), then they will be reported on in the console after the suite completes.
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
.......... 10 / 10 (100%)
Recorded 6 slow tests:
1. 516ms to run ExampleTest:testSomething (expected <500ms)
2. 1004ms to run ExampleTest:testTest with data set "e" (expected <800ms)
3. 1000ms to run ExampleTest:testTest with data set "d" (expected <800ms)
4. 1002ms to run ExampleTest:testTest with data set "c" (expected <800ms)
5. 1004ms to run ExampleTest:testTest with data set "b" (expected <800ms)
6. 1005ms to run ExampleTest:testTest with data set "a" (expected <800ms)
Time: 10.24 seconds, Memory: 4.00MB
Configuration
Within the configuration a number of arguments can optionally be passed to the test listener.
<phpunit bootstrap="vendor/autoload.php"> <listeners> <listener class="Keystone\PHPUnit\BroomWagon\TestListener"> <arguments> <!-- Suite threshold --> <integer>100</integer> <!-- Group thresholds --> <array> <element key="database"> <integer>1000</integer> </element> <element key="browser"> <integer>5000</integer> </element> </array> <!-- Report length --> <integer>10</integer> </arguments> </listener> </listeners> </phpunit>
Suite threshold (default 500ms):
The first argument is the overall suite threshold. This is the number of milliseconds a test can take to execute before it is deemed as slow.
Group thresholds:
The second argument is an array of group thresholds. Each test @group
annotation can have a different threshold. A use case for this is to group all tests that hit the database and be a little more relaxed with the slow threshold.
Report length (default 10):
The third argument is the number of slow tests to display in the PHPUnit output.
Annotations
The @slowThreshold
annotation can be added to test classes or test methods to override any suite or group thresholds.
/** * @slowThreshold 2000 */ class SomeTestCase extends \PHPUnit_Framework_TestCase { /** * @slowThreshold 5000 */ public function testLongRunningProcess() { } }
Credits
License
Released under the MIT Licence. See the bundled LICENSE file for details.