PHPUnit TestSuite排除

Tim*_*eph 13 php phpunit unit-testing

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

<testsuite name="PHPUnitWillKillMe">   
    <directory>src/*/Bundle/*/*Bundle/Tests</directory>
    <exclude>src/*/Bundle/*/*Bundle/Tests/Controller/</exclude>
</testsuite>   
Run Code Online (Sandbox Code Playgroud)

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

问题是,它不起作用.当我运行时,PHPUnit仍然在src// Bundle //*Bundle/Tests/Controller /中运行所有测试

 phpunit --testsuite PHPUnitWillKillMe
Run Code Online (Sandbox Code Playgroud)

任何的想法?

最好的祝福!

我测试的PHPUnit版本是3.7.21和3.7.28.

ach*_*zot 11

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

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>
Run Code Online (Sandbox Code Playgroud)

这是我发现根据需要排除测试的唯一方法MyBundle.全球化不适用于exclude.但是,这意味着您必须添加与exclude要忽略的文件夹一样多的指令.

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

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

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


lch*_*ski 5

刚刚有类似的问题,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.
...
Run Code Online (Sandbox Code Playgroud)

你做的是

/**
 * @group nonRunnableGroupName
 */
public function testSomething()
{ /* test here */ }
Run Code Online (Sandbox Code Playgroud)

并运行测试

$ phpunit -c /src --exclude-group nonRunnableGroupName
Run Code Online (Sandbox Code Playgroud)