如何运行特定的 phpunit xml 测试套件?
我如何选择要执行的特定测试套件?
$ phpunit --配置config.xml
config.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>
how can i choose a specific testsuite to be executed?
$ phpunit --configuration config.xml
config.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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这里的代码就像 PHPUnit 3.7.13
如果你想运行一组测试套件那么你可以这样做
然后
不幸的是 PHPUnit 目前不支持这样的嵌套测试套件
所以如果你想以这种方式运行一组测试套件你有有xml配置重复!
Here's the code as if PHPUnit 3.7.13
If you want to run a group of the test suites then you can do this
Then
Unfortunately PHPUnit currently does not support nested testsuites like this
So if you wanted to run groups of test suites this way you have to have xml configuration duplication!
这在当前版本的 PHPUnit 中是不可能的,正如 phpunit-user 邮件列表中的这些消息所证明的那样: http://thread.gmane.org/gmane.comp.php.phpunit.user/1302
但是还有一种替代方法,您可以简单地将路径传递给 phpunit。
这将运行library/XXX目录中的所有测试
如果这对您来说还不够,另一个选择是使用@group 注释 将测试分为不同的类别,然后可以有选择地运行。
This is not possible in current versions of PHPUnit as evidenced by these messages in phpunit-user mailing list: http://thread.gmane.org/gmane.comp.php.phpunit.user/1302
But there is an alternative, you can simply pass a path to phpunit.
This would run all the tests in library/XXX directory
If this is not sufficient for you, another option is to use the @group annotation to divide tests into different categories that could then be run selectively.
从 phpunit 6.1 开始,您可以在 xml 配置文件中使用属性
defaultTestSuite
,这就像使用默认选项phpunit --testsuite xxx
一样,并且会被覆盖。As of phpunit 6.1 you can use in the xml config file the attribute
defaultTestSuite
, this is like using a default optionphpunit --testsuite xxx
and is overriden.另一种选择是为您想要单独测试的每个测试套件创建一个单独的配置文件。您可能需要复制/粘贴重复的设置,因此会产生一些开销,但您可以根据需要指定每个配置文件。
Another option is to create a separate config file for each testsuite you would like to test separately. There is some overhead in that you may have to copy/paste duplicate settings, but you could then specify each config file as needed.
这里的其他答案是正确的。你不能使用 xml 配置来做到这一点,但你可以做的是在 php 中进行相同类型的配置。
它当然不是最漂亮的东西,但它应该为您提供所需的功能。
您提供了 xml 配置
假设您的目录“library”包含 3 个文件:
每个文件都包含 1 个按完美命名约定的测试,例如: FormTest 包含 testForm()
对于配置,我们将创建一个包含everything:
然后我们将按照 phpunit 命名约定创建一个类。您可以将其命名为您想要的任何名称,因为我们永远不会实际使用它...
每个“测试套件”只是运行您想要的测试的方法。将方法命名为您想要的任何名称,因为我们永远不会真正使用它。 Phunit 将负责运行。不过,请务必将它们分组注释,以便您知道如何执行。
现在,为了获得您想要的功能,只需针对您想要的组运行“配置”即可。
正如我所说,这是丑陋的,而且肯定不是好的代码,因为它需要不断的维护,
但它会给你你正在寻找的功能。
希望 Bergmann 在下一轮中添加此功能,尽管这似乎不太可能,因为他看起来几乎是 忽略它。
The other answers here are correct. You can't do this using an xml config, what you can do though is make the same type of config in php.
It's certainly not the prettiest thing, but it should give you the functionality you would need.
You provided the xml config
Hypothetically, let's say your directory "library" contains 3 files:
And that each of the files contains 1 test by perfect naming convention, eg: FormTest contains testForm()
For the config we'll create a config that contains everything:
Then we'll create a class by the phpunit naming conventions. You can name it whatever you want as we'll never actually use it...
Each "test suite" will simply be a method that runs the tests you want. Name the methods whatever you want as, once again, we'll never actually use it. Phpunit will take care of the running. Be sure to comment them into groups though so you know how to execute.
Now in order to get the functionality you want just run the "config" against the group you want.
As I said, this is ugly and certainly not good code as it will require constant maintenance,
but it will give you the functionality you're looking for.
Hopefully Bergmann will add this functionality in his next round although it doesn't seem likely as he appears to pretty much be ignoring it.