PHPackages                             ergebnis/phpunit-slow-test-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. ergebnis/phpunit-slow-test-detector

ActiveLibrary[Testing &amp; Quality](/categories/testing)

ergebnis/phpunit-slow-test-detector
===================================

Provides facilities for detecting slow tests in phpunit/phpunit.

2.24.0(2mo ago)1468.1M↓12.9%12[8 issues](https://github.com/ergebnis/phpunit-slow-test-detector/issues)[7 PRs](https://github.com/ergebnis/phpunit-slow-test-detector/pulls)20MITPHPPHP ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Feb 3Pushed today4 watchersCompare

[ Source](https://github.com/ergebnis/phpunit-slow-test-detector)[ Packagist](https://packagist.org/packages/ergebnis/phpunit-slow-test-detector)[ Docs](https://github.com/ergebnis/phpunit-slow-test-detector)[ RSS](/packages/ergebnis-phpunit-slow-test-detector/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (53)Used By (20)

phpunit-slow-test-detector
==========================

[](#phpunit-slow-test-detector)

[![Integrate](https://github.com/ergebnis/phpunit-slow-test-detector/workflows/Integrate/badge.svg)](https://github.com/ergebnis/phpunit-slow-test-detector/actions)[![Merge](https://github.com/ergebnis/phpunit-slow-test-detector/workflows/Merge/badge.svg)](https://github.com/ergebnis/phpunit-slow-test-detector/actions)[![Nightly](https://github.com/ergebnis/phpunit-slow-test-detector/workflows/Nightly/badge.svg)](https://github.com/ergebnis/phpunit-slow-test-detector/actions)[![Release](https://github.com/ergebnis/phpunit-slow-test-detector/workflows/Release/badge.svg)](https://github.com/ergebnis/phpunit-slow-test-detector/actions)[![Renew](https://github.com/ergebnis/phpunit-slow-test-detector/workflows/Renew/badge.svg)](https://github.com/ergebnis/phpunit-slow-test-detector/actions)

[![Code Coverage](https://camo.githubusercontent.com/cae02e528ee09f4d26b05be950da2a2cf12ab239e4926c3345d1e2568080b4dd/68747470733a2f2f636f6465636f762e696f2f67682f65726765626e69732f706870756e69742d736c6f772d746573742d6465746563746f722f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/ergebnis/phpunit-slow-test-detector)

[![Latest Stable Version](https://camo.githubusercontent.com/b027d8f5168d4adc65cc36d0afd26e20236dcdd4af9009bbd8b4bc5e4731d87f/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f706870756e69742d736c6f772d746573742d6465746563746f722f762f737461626c65)](https://packagist.org/packages/ergebnis/phpunit-slow-test-detector)[![Total Downloads](https://camo.githubusercontent.com/2640c743935765b1bae2580d4132daaa8d5832ba3f91f7f3244ebc28214f3fe5/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f706870756e69742d736c6f772d746573742d6465746563746f722f646f776e6c6f616473)](https://packagist.org/packages/ergebnis/phpunit-slow-test-detector)[![Monthly Downloads](https://camo.githubusercontent.com/a9c3d8c2bf06587b882dd1cdef227e7299167a3a29bc0404495cf29dada78e9f/687474703a2f2f706f7365722e707567782e6f72672f65726765626e69732f706870756e69742d736c6f772d746573742d6465746563746f722f642f6d6f6e74686c79)](https://packagist.org/packages/ergebnis/phpunit-slow-test-detector)

This project provides a [`composer`](https://getcomposer.org) package and a [Phar archive](https://www.php.net/manual/en/book.phar.php) with an extension for detecting slow tests in [`phpunit/phpunit`](https://github.com/sebastianbergmann/phpunit).

Example
-------

[](#example)

After installing, configuring, and bootstrapping the extension, when running your tests with `phpunit/phpunit`, the extension will report slow tests:

```
PHPUnit 10.0.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.0
Configuration: test/EndToEnd/Default/phpunit.xml
Random Seed:   1676103726

.............                                                                                                                                                                                                                                                                                                   13 / 13 (100%)

Detected 11 tests where the duration exceeded the global maximum duration (0.500).

 # Duration Test
----------------------------------------------------------------------------------------------------------------------------------------------------
 1    1.604 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#9
 2    1.505 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#8
 3    1.403 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#7
 4    1.303 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#6
 5    1.205 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#5
 6    1.103 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#4
 7    1.005 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3
 8    0.905 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2
 9    0.805 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1
10    0.705 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#0
----------------------------------------------------------------------------------------------------------------------------------------------------
      0.000
       └─── seconds

There is 1 additional slow test that is not listed here.

Time: 00:12.601, Memory: 8.00 MB

OK (13 tests, 13 assertions)
```

Compatibility
-------------

[](#compatibility)

The extension is compatible with the following versions of `phpunit/phpunit`:

- [`phpunit/phpunit:^13.0.0`](https://github.com/sebastianbergmann/phpunit/tree/13.0.0)
- [`phpunit/phpunit:^12.0.0`](https://github.com/sebastianbergmann/phpunit/tree/12.0.0)
- [`phpunit/phpunit:^11.0.0`](https://github.com/sebastianbergmann/phpunit/tree/11.0.0)
- [`phpunit/phpunit:^10.0.0`](https://github.com/sebastianbergmann/phpunit/tree/10.0.0)
- [`phpunit/phpunit:^9.0.0`](https://github.com/sebastianbergmann/phpunit/tree/9.0.0)
- [`phpunit/phpunit:^8.5.19`](https://github.com/sebastianbergmann/phpunit/tree/8.5.19)
- [`phpunit/phpunit:^7.5.0`](https://github.com/sebastianbergmann/phpunit/tree/7.5.0)
- [`phpunit/phpunit:^6.5.0`](https://github.com/sebastianbergmann/phpunit/tree/6.5.0)

Installation
------------

[](#installation)

### Installation with `composer`

[](#installation-with-composer)

Run

```
composer require --dev ergebnis/phpunit-slow-test-detector
```

to install `ergebnis/phpunit-slow-test-detector` as a `composer` package.

### Installation as Phar

[](#installation-as-phar)

Download `phpunit-slow-test-detector.phar` from the [latest release](https://github.com/ergebnis/phpunit-slow-test-detector/releases/latest).

Usage
-----

[](#usage)

### Bootstrapping the extension

[](#bootstrapping-the-extension)

Before the extension can detect slow tests in `phpunit/phpunit`, you need to bootstrap it. The bootstrapping mechanism depends on the version of `phpunit/phpunit` you are using.

### Bootstrapping the extension as a `composer` package

[](#bootstrapping-the-extension-as-a-composer-package)

To bootstrap the extension as a `composer` package when using

- `phpunit/phpunit:^13.0.0`
- `phpunit/phpunit:^12.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^10.0.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensions` element](https://docs.phpunit.de/en/13.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^13.0.0`](https://docs.phpunit.de/en/13.0/)
- [`extensions` element](https://docs.phpunit.de/en/12.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^12.0.0`](https://docs.phpunit.de/en/12.0/)
- [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)
- [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)

```

+
+
+

             test/Unit/

```

---

To bootstrap the extension as a `composer` package when using

- `phpunit/phpunit:^9.0.0`
- `phpunit/phpunit:^8.5.19`
- `phpunit/phpunit:^7.5.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensions` element](https://docs.phpunit.de/en/9.6/configuration.html#the-extensions-element) on [`phpunit/phpunit:^9.0.0`](https://docs.phpunit.de/en/9.6/)
- [`extensions` element](https://docs.phpunit.de/en/8.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^8.5.19`](https://docs.phpunit.de/en/8.5/)
- [`extensions` element](https://docs.phpunit.de/en/7.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^7.5.0`](https://docs.phpunit.de/en/7.5/)

```

+
+
+

             test/Unit/

```

---

To bootstrap the extension as a `composer` package when using

- `phpunit/phpunit:^6.5.0`

adjust your `phpunit.xml` configuration file and configure the

- [`listeners` element](https://phpunit.de/manual/6.5/en/appendixes.configuration.html#appendixes.configuration.test-listeners) on [`phpunit/phpunit:^6.5.0`](https://phpunit.de/manual/6.5/en/)

```

+
+
+

             test/Unit/

```

### Bootstrapping the extension as a PHAR

[](#bootstrapping-the-extension-as-a-phar)

To bootstrap the extension as a PHAR when using

- `phpunit/phpunit:^13.0.0`
- `phpunit/phpunit:^12.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^10.0.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/13.0/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/13.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^13.0.0`](https://docs.phpunit.de/en/13.0/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/12.0/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/12.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^12.0.0`](https://docs.phpunit.de/en/12.0/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/11.0/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.5/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)

```

+
+
+

             test/Unit/

```

---

To bootstrap the extension as a PHAR when using

- `phpunit/phpunit:^9.0.0`
- `phpunit/phpunit:^8.5.19`
- `phpunit/phpunit:^7.5.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/9.6/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/9.6/configuration.html#the-extensions-element) on [`phpunit/phpunit:^9.0.0`](https://docs.phpunit.de/en/9.5/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/8.5/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/8.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^8.5.19`](https://docs.phpunit.de/en/8.5/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/7.5/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/7.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^7.5.0`](https://docs.phpunit.de/en/7.5/)

```

+
+
+

             test/Unit/

```

### Configuring the extension

[](#configuring-the-extension)

You can configure the extension with the following options in your `phpunit.xml` configuration file:

- `maximum-count`, an `int`, the maximum count of slow test that should be reported, defaults to `10`
- `maximum-duration`, an `int`, the maximum duration in milliseconds for a test before the extension considers it as a slow test, defaults to `500`
- `stderr`, a `bool`, directs the slow test report output to `stderr`, defaults to `false`, only available on `phpunit/phpunit:^6.5.0`, `phpunit/phpunit:^7.5.0`, `phpunit/phpunit:^8.5.19`, and `phpunit/phpunit:^9.0.0` (on `phpunit/phpunit:^10.0.0` and later, the extension automatically respects the `stderr` configuration `phpunit/phpunit`)

The configuration mechanism depends on the version of `phpunit/phpunit` you are using.

### Configuring the extension

[](#configuring-the-extension-1)

To configure the extension when using

- `phpunit/phpunit:^13.0.0`
- `phpunit/phpunit:^12.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^10.0.0`

adjust your `phpunit.xml` configuration file and configure one or more

- [`parameter` elements](https://docs.phpunit.de/en/13.0/configuration.html#the-parameter-element) on [`phpunit/phpunit:^13.0.0`](https://docs.phpunit.de/en/13.0/)
- [`parameter` elements](https://docs.phpunit.de/en/12.0/configuration.html#the-parameter-element) on [`phpunit/phpunit:^12.0.0`](https://docs.phpunit.de/en/12.0/)
- [`parameter` elements](https://docs.phpunit.de/en/11.0/configuration.html#the-parameter-element) on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)
- [`parameter` elements](https://docs.phpunit.de/en/10.5/configuration.html#the-parameter-element) on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)

The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds:

```

-
+
+
+
+

             test/Unit/

```

---

To configure the extension when using

- `phpunit/phpunit:^9.0.0`
- `phpunit/phpunit:^8.5.19`
- `phpunit/phpunit:^7.5.0`

adjust your `phpunit.xml` configuration file and configure the

- [`arguments` element](https://docs.phpunit.de/en/9.6/configuration.html#the-arguments-element) on [`phpunit/phpunit:^9.0.0`](https://docs.phpunit.de/en/9.6/)
- [`arguments` element](https://docs.phpunit.de/en/8.5/configuration.html#the-arguments-element) on [`phpunit/phpunit:^8.5.19`](https://docs.phpunit.de/en/8.5/)
- [`arguments` element](https://docs.phpunit.de/en/7.5/configuration.html#the-arguments-element) on [`phpunit/phpunit:^7.5.0`](https://docs.phpunit.de/en/7.5/)

The following example configures the maximum count of slow tests to three, the maximum duration for all tests to 250 milliseconds, and directs the slow test report output to `stderr`:

```

-
+
+
+
+
+                        3
+
+
+                        250
+
+
+                        true
+
+
+
+

             test/Unit/

```

---

To configure the extension when using

- `phpunit/phpunit:^6.5.0`

adjust your `phpunit.xml` configuration file and configure the

- [`arguments` element](https://phpunit.de/manual/6.5/en/appendixes.configuration.html#appendixes.configuration.test-listeners) on [`phpunit/phpunit:^6.5.0`](https://phpunit.de/manual/6.5/en/)

The following example configures the maximum count of slow tests to three, the maximum duration for all tests to 250 milliseconds, and directs the slow test report output to `stderr`:

```

-
+
+
+
+
+                        3
+
+
+                        250
+
+
+                        true
+
+
+
+

             test/Unit/

```

### Configuring the maximum duration per test case

[](#configuring-the-maximum-duration-per-test-case)

You can configure the maximum duration for a single test case with

- an `Attribute\MaximumDuration` attribute when using
    - `phpunit/phpunit:^13.0.0`
    - `phpunit/phpunit:^12.0.0`
    - `phpunit/phpunit:^11.0.0`
    - `phpunit/phpunit:^10.0.0`
- a `@maximumDuration` annotation in the DocBlock when using
    - `phpunit/phpunit:^9.0.0`
    - `phpunit/phpunit:^8.5.19`
    - `phpunit/phpunit:^7.5.0`
    - `phpunit/phpunit:^6.5.0`
- a `@slowThreshold` annotation in the DocBlock when using
    - `phpunit/phpunit:^9.0.0`
    - `phpunit/phpunit:^8.5.19`
    - `phpunit/phpunit:^7.5.0`
    - `phpunit/phpunit:^6.5.0`

The following example configures the maximum durations for single test cases to 5,000 ms, 4,000 ms, and 3,000 ms:

```
