问题 PHPUnit TestSuite排除


所以我想从我的Testsuite中排除一个directoy,就像这样:

<testsuite name="PHPUnitWillKillMe">   
    <directory>src/*/Bundle/*/*Bundle/Tests</directory>
    <exclude>src/*/Bundle/*/*Bundle/Tests/Controller/</exclude>
</testsuite>   

应该测试除控制器之外的所有东西。

问题是,它不起作用。 PHPUnit仍在src /中运行所有测试/束// * Bundle / Tests / Controller /我跑的时候

 phpunit --testsuite PHPUnitWillKillMe

任何想法?

最好的祝福!

我测试过的PHPUnit版本是3.7.21和3.7.28。


13165
2018-03-25 20:52


起源

这个以前的“解决方案”怎么样 stackoverflow.com/questions/2736343/... ? - achedeuzot
我不这么认为,看 phpunit.de/manual/3.7/en/appendixes.configuration.html  - >测试套件 - Tim Joseph


答案:


我在我的Symfony演示项目上测试了它 Bundles 表明这是你正在使用的)我有同样的问题。这似乎是两个问题的结合。首先,运行PHPUnit(PHPUnit 3.7.19)的一个已知错误 -c 要么 --config 选项:

https://github.com/sebastianbergmann/phpunit/issues/928

在其他地方运行并使用--config指定配置文件时,排除将停止工作。

第二, exclude 当有任何globbing时,指令似乎忽略/失败(*)在路径中,所以通过删除globbing,它对我有用:

<testsuites>
    <testsuite name="Project Test Suite">
        <directory>../src/*/*Bundle/Tests</directory>
        <directory>../src/*/Bundle/*Bundle/Tests</directory>
        <exclude>../src/Blah/MyBundle/Tests/Controller/</exclude>
    </testsuite>
</testsuites>

就是这样 只要 我发现排除测试的方式 MyBundle 按要求。全球化了  为...工作 exclude。但是,这意味着你必须添加更多 exclude 指令,因为有想要忽略的文件夹。

可能相关的gihub问题: https://github.com/sebastianbergmann/phpunit/pull/573

[...]这个修复程序登陆4.0版本,因为它打破了向后兼容性。

  • 解决方案#1:删除路径中的任何globbing
  • 解决方案#2:升级到PHPUnit v4。*(未经我自己测试,请参阅注释,并未解决问题 exclude 带有globbing的路径)

9
2018-03-25 20:57



这仅适用于代码覆盖率报告,而不适用于运行测试... - Tim Joseph
我更新了我的答案:) - achedeuzot
我不知道怎么样。我甚至可以尝试以下内容,它仍将在目录<directory> ../ src / * / Bundle / * / * Bundle / Tests </ directory> <exclude> ../ src / * / Bundle /中运行所有测试* / *捆绑/测试</ exclude>您遇到同样的问题吗?对于PHPUnit版本,请参阅更新的问题 - Tim Joseph
我刚刚测试过,我有 精确 同样的问题。有关详细信息,请参阅答案 - achedeuzot
非常感谢你。我已经在github上发现了这个问题,但也许我很愚蠢或者我的英语不好,但现在的解决方案是什么?我不知道......或者解决方法是更新到4.0。*? - Tim Joseph


刚刚有类似的问题,phpunit对群组有很好的支持:

...
--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.
...

你做的是

/**
 * @group nonRunnableGroupName
 */
public function testSomething()
{ /* test here */ }

并运行测试

$ phpunit -c /src --exclude-group nonRunnableGroupName

5
2017-09-30 13:53