php - PHPUnit TestSuite排除

标签 php unit-testing phpunit

所以我想像这样从我的Testsuite中排除Directoy:

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

除 Controller 外的所有物品都应进行测试。

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

任何的想法?

最好的祝福!

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

最佳答案

我在Symfony演示项目上对其进行了测试(Bundles表示这就是您正在使用的),但我遇到了同样的问题。这似乎是两个问题的结合。首先,使用-c--config选项运行PHPUnit(PHPUnit 3.7.19)存在一个已知的错误:

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

When running it elsewhere and specifying the config file using --config, the exclude would however stop working.



其次,当路径中存在任何通配符(exclude)时,*指令似乎会忽略/失败,因此通过删除通配符,它​​对我有用:
<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,globbing的不起作用,不起作用。但是,这意味着您必须添加与要忽略的文件夹一样多的exclude指令。

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

[...] this fix lands in the 4.0 release as it breaks backwards compatibility.


  • 解决方案#1:删除路径中的所有lob
  • 解决方案2:升级到PHPUnit v4。*(未经本人测试,请参见注释,无法解决lobt的exclude路径问题)
  • 关于php - PHPUnit TestSuite排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22645986/

    相关文章:

    php - 如何在 Docker 容器中测试 PHP API

    php - 在 Woocommerce 中为每 3 件商品的统一运费增加额外费用

    php - Google OAuth - 私有(private) IP 需要 device_id 和 device_name

    php - 提交后如何将变量从javascript传递给php

    unit-testing - 单元测试成为 TDD 的集成测试

    php - 有没有办法提高 mysqli->prepare 的执行速度?

    php - Symfony 2 - 顶部菜单未出现在 Sonata admin 中

    javascript - 如何在 Mocha 测试中模拟全局变量(定义、模块、窗口)?

    c# - 在 NUnit 测试中创建 App Domain 时出现异常

    php - 在 phpunit.xml 中将进程隔离设置为 false 会导致 Laravel 功能测试失败