keystone/phpunit-broom-wagon

在您的PHPUnit测试套件中查找缓慢运行的测试。

1.0.0 2017-02-05 20:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:27:20 UTC


README

A PHPUnit测试监听器,报告缓慢运行的测试。从 johnkary/phpunit-speedtrap 分支,以便对缓慢阈值有更多控制,并支持PHPUnit 5。

扫帚车?

扫帚车是指跟随自行车公路赛并在规定时间内未能到达终点的人“清扫”的车辆。作为一个骑自行车的人,我觉得这个名字很有意义。

Broom wagon

安装

通过Composer安装

composer require --dev keystone/phpunit-broom-wagon

用法

通过将其添加到您的 phpunit.xml 配置文件中来启用监听器。

<phpunit bootstrap="vendor/autoload.php">
    <listeners>
        <listener class="Keystone\PHPUnit\BroomWagon\TestListener" />
    </listeners>
</phpunit>

现在正常运行您的测试套件。如果测试时间超过缓慢阈值(默认为500ms),则在套件完成后,将在控制台报告中报告。

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

配置

在配置中,可以可选地向测试监听器传递多个参数。

<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>

套件阈值(默认500ms)

第一个参数是整体套件阈值。测试在被视为缓慢之前可以执行的毫秒数。

组阈值:

第二个参数是一组阈值数组。每个测试@group注释可以有不同的阈值。这个用例是将所有触碰到数据库的测试分组,并对缓慢阈值更加宽松。

报告长度(默认10)

第三个参数是显示在PHPUnit输出中的缓慢测试数量。

注释

@slowThreshold注释可以添加到测试类或测试方法中,以覆盖任何套件或组阈值。

/**
 * @slowThreshold 2000
 */
class SomeTestCase extends \PHPUnit_Framework_TestCase
{
    /**
     * @slowThreshold 5000
     */
    public function testLongRunningProcess()
    {
    }
}

致谢

许可证

在MIT许可证下发布。有关详细信息,请参阅捆绑的LICENSE文件。