我正在将 phpunit 与 jenkins 结合使用,我想通过在 XML 文件中设置配置来跳过某些测试
phpunit.xml
我知道我可以在命令行上使用:
phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest
如何将其转换为 XML 文件,因为
<filters>
标签仅用于代码覆盖?
我想运行除
testStuffThatAlwaysBreaks
之外的所有测试
跳过已损坏的测试或稍后需要继续工作的测试的最快、最简单的方法是将以下内容添加到单个单元测试的顶部:
$this->markTestSkipped('must be revisited.');
如果您可以忽略整个文件,那么
<?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>
有时,根据定义为 php 代码的自定义条件跳过特定文件中的所有测试很有用。您可以使用 setUp 函数轻松地做到这一点,其中 makeTestSkipped 也可以工作。
protected function setUp()
{
parent::setUp();
if (your_custom_condition) {
$this->markTestSkipped('all tests in this file are invactive for this server configuration!');
}
}
your_custom_condition 可以通过一些静态类方法/属性、phpunit bootstrap 文件中定义的常量甚至全局变量来传递。
注意:不要忘记致电
parent::setUp()
(请参阅文档)。