使PHPUnit忽略事物? [英] Making PHPUnit ignore things?

查看:74
本文介绍了使PHPUnit忽略事物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHPUnit Test类,希望从测试运行中忽略它.我知道我可以通过重命名来做到这一点,以便它的文件名中不包含单词Test,但是我不愿意这样做,因为它会使源代码控制范围更加混乱.

I have a PHPUnit Test class that I'd like to be ignored from a test run. I know I can do it by renaming it so that it doesn't contain the word Test in its filename, but I'd rather not do that since it muddies up the source control waters more than I'd like.

有人建议吗?

推荐答案

phpunit命令有两个选项,可以帮助定义应该和不应该运行哪些测试:

There are a couple of options for the phpunit command that can help define which tests should and should not be run :

$ phpunit --help
PHPUnit 3.4.0beta5 by Sebastian Bergmann.

Usage: phpunit [switches] UnitTest [UnitTest.php]
       phpunit [switches] <directory>
...
  --filter <pattern>       Filter which tests to run.
  --group ...              Only runs tests from the specified group(s).
  --exclude-group ...      Exclude tests from the specified group(s).
  --list-groups            List available test groups.
...

这些人可能不允许确切地指定您想要的内容...但是它们可能会有所帮助.

Those will probably not allow to specify exactly what you wanted... But they might help.

有关更多详细信息,请参见命令行测试运行器

For more details, see The Command-Line Test Runner


特别是,我有点喜欢分组功能:只需在测试的phpdoc中使用@group标记,即可将它们重新分组(例如,每个功能块"一组);然后,您可以在命令行上使用--group--exclude-group选项来指定应该或不应该运行哪些测试.


Especially, I kind of like the group feature : just use a @group tag in the phpdoc of your tests, to re-group them (for instance, one group per "chunk of functionnality") ; and, after, you can use the --group or --exclude-group options on the command line to specify which tests should or shouldn't be run.

在您的情况下,如果您无法修改测试,则--filter选项可能会有所帮助,具体取决于您对测试的命名方式(即,是否有一种方法可以标识要运行的测试):

In your case, if you cannot modify the tests, maybe the --filter option can help, depending on how your tests are nammed (ie, if there is a way to identify those you want to run) :

--filter
仅运行名称与给定模式匹配的测试.图案可以是 单个测试的名称或 匹配的正则表达式 多个测试名称.

--filter
Only runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names.


如果您不总是更改要运行的测试的组",另一种解决方案可能是使用仅包含要运行的测试的测试套件.


Another solution, if you are not always changing the "groups" of tests to run, might be to use a test-suite that only includes the tests you want to run.

例如,看看使用XML配置组成测试套件.

这篇关于使PHPUnit忽略事物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆