其他答案在这里是正确的。你不能使用xml配置来做到这一点,但你可以做的是在php中使用相同类型的配置。
这当然不是最漂亮的事情,但它应该给你你需要的功能。
您提供的XML配置
<testsuites>
<testsuite name="Library">
<directory>library</directory>
</testsuite>
<testsuite name="XXX_Form">
<file>library/XXX/FormTest.php</file>
<directory>library/XXX/Form</directory>
</testsuite>
</testsuites>
可以想像,假设你的目录下的“库”包含3个文件:
library
XXX
FormTest.php
Unit
unittest1.php
unittest2.php
,并且每个文件包含了完美的命名惯例1次测试,例如:FormTest包含testForm()
对于配置我们将创建一个包含所有内容的配置:
<?php
include_once "library/XXX/FormTest.php";
include_once "library/Unit/unittest1.php";
include_once "library/Unit/unittest2.php";
然后,我们将创建由PHPUnit的命名约定的类。你可以将其命名为任何你想要的,我们永远不会真正使用它......
class LibraryConfigTest extends PHPUnit_Framework_TestCase {
每个“测试套件”将仅仅是运行要测试的方法。无论你想要什么,都要命名这些方法,再一次,我们永远不会使用它。 Phpunit将负责运行。一定要将他们评论成组,尽管你知道如何执行。
/**
* All Tests in Library
* @group Library
**/
public function testLibrary() {
UnitTest1::testUnit1();
UnitTest2::testUnit2();
FormTest::testForm();
}
/**
* All Form tests in library/XXX
* @group XXX_Form
**/
public function testForm() {
FormTest::testForm();
}
}
?>
现在为了获得您想要的功能,您只需针对所需的组运行“config”。
phpunit --group XXX_Form library_config.php
phpunit --group Library library_config.php
正如我所说的,这是丑陋的,当然不是好代码,因为这将需要定期的维护, 但它会给你你正在寻找的功能。
希望Bergmann会在他的下一轮中增加这个功能,尽管看起来似乎不太可能,因为他看起来几乎是ignoring it。
X-Ref:[在PHPUnit中默认运行单个测试套件](https://stackoverflow.com/q/37820193/367456) – hakre 2017-08-02 21:45:20