108

我正在将 phpunit 与 jenkins 结合使用,并且我想通过在 XML 文件中设置配置来跳过某些测试phpunit.xml

我知道我可以在命令行上使用:

phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest

<filters>由于标签仅用于代码覆盖,如何将其转换为 XML 文件?

我想运行所有测试除了testStuffThatAlwaysBreaks

4

3 回答 3

208

跳过已损坏或您需要稍后继续工作的测试的最快和最简单的方法是将以下内容添加到单个单元测试的顶部:

$this->markTestSkipped('must be revisited.');
于 2012-05-06T18:19:43.883 回答
36

如果您可以处理忽略整个文件,那么

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>

    <testsuites>
        <testsuite name="foo">
            <directory>./tests/</directory>
            <exclude>./tests/path/to/excluded/test.php</exclude>
                ^-------------
        </testsuite>
    </testsuites>

</phpunit>
于 2012-04-20T03:45:26.490 回答
23

有时,根据定义为 php 代码的自定义条件跳过特定文件中的所有测试很有用。您可以使用 setUp 函数轻松地做到这一点,其中 makeTestSkipped 也可以工作。

protected function setUp()
{
    if (your_custom_condition) {
        $this->markTestSkipped('all tests in this file are invactive for this server configuration!');
    }
}

your_custom_condition can be passed via some static class method/property, a constant defined in phpunit bootstrap file or even a global variable.

于 2016-02-09T09:44:19.520 回答