I am using phpunit in connection with jenkins, and I want to skip certain tests by setting the configuration in the XML file phpunit.xml
我正在使用phpunit与jenkins连接,我想通过在XML文件phpunit.xml中设置配置来跳过某些测试
I know that I can use on the command line:
我知道我可以在命令行上使用:
phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest
phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest
how do I translate that to the XML file since the <filters>
tag is only for code-coverage?
我如何将其转换为XML文件,因为
I would like to run all tests apart from testStuffThatAlwaysBreaks
我想运行除testStuffThatAlwaysBreaks之外的所有测试
3 个解决方案
#1
98
The fastest and easiest way to skip tests that are either broken or you need to continue working on later is to just add the following to the top of your individual unit test:
跳过要么已损坏或需要继续处理的测试的最快最简单的方法是将以下内容添加到单个单元测试的顶部:
$this->markTestSkipped('must be revisited.');
#2
21
If you can deal with ignoring the whole file then
如果你可以处理忽略整个文件然后
<?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>
#3
8
Sometimes it's useful to skip all tests from particular file based on custom condition(s) defined as php code. You can easily do that using setUp function in which makeTestSkipped works as well.
有时,基于定义为php代码的自定义条件,跳过特定文件中的所有测试是有用的。您可以使用setUp函数轻松完成此操作,其中makeTestSkipped也可以使用。
protected function setUp()
{
if (Config::getInstance()->myConfigCondition == false) {
$this->markTestSkipped('all tests in this file are invactive for this server configuration!');
}
}
Btw phpunit 5.2 stable official documentation suggests that you should use markTestSkipped as instance method, not a static method. Didn't check if definition was changed along the way.
顺便说一句phpunit 5.2稳定的官方文档建议你应该使用markTestSkipped作为实例方法,而不是静态方法。没有检查定义是否在此过程中发生了变化。
#1
98
The fastest and easiest way to skip tests that are either broken or you need to continue working on later is to just add the following to the top of your individual unit test:
跳过要么已损坏或需要继续处理的测试的最快最简单的方法是将以下内容添加到单个单元测试的顶部:
$this->markTestSkipped('must be revisited.');
#2
21
If you can deal with ignoring the whole file then
如果你可以处理忽略整个文件然后
<?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>
#3
8
Sometimes it's useful to skip all tests from particular file based on custom condition(s) defined as php code. You can easily do that using setUp function in which makeTestSkipped works as well.
有时,基于定义为php代码的自定义条件,跳过特定文件中的所有测试是有用的。您可以使用setUp函数轻松完成此操作,其中makeTestSkipped也可以使用。
protected function setUp()
{
if (Config::getInstance()->myConfigCondition == false) {
$this->markTestSkipped('all tests in this file are invactive for this server configuration!');
}
}
Btw phpunit 5.2 stable official documentation suggests that you should use markTestSkipped as instance method, not a static method. Didn't check if definition was changed along the way.
顺便说一句phpunit 5.2稳定的官方文档建议你应该使用markTestSkipped作为实例方法,而不是静态方法。没有检查定义是否在此过程中发生了变化。