【问题标题】:PHPUnit - Running a particular test suite via the command line test runner [duplicate]PHPUnit - 通过命令行测试运行程序运行特定的测试套件[重复]
【发布时间】:2011-05-18 23:41:21
【问题描述】:

是否可以通过命令行测试运行程序从配置文件中指定要运行的测试套件?例如,如果我有以下 xml 配置:

<phpunit ...>
    <testsuites>
        <testsuite name="My Test Suite 1">
            <directory>./MyTestSuite1/</directory>
        </testsuite>
        <testsuite name="My Test Suite 2">
            <directory>./MyTestSuite2/</directory>
        </testsuite>
    </testsuites>
    ...
</phpunit>

我可以让它只运行“我的测试套件 1”吗?

【问题讨论】:

  • 我知道你可以从 Testcase 中单独测试。不过不确定套房。尝试做类似phpunit Suitename Path/To/AllSuites.php 或其他方式的事情。另外,检查phpunit --helpphpunit.de/manual/3.4/en/textui.html

标签: php unit-testing phpunit


【解决方案1】:

我是phpunit --testsuite "My Test Suite 1"

【讨论】:

  • --testsuite 标志直到 3.7 才存在
  • 注意有保留关键字,例如使用“目录”作为测试套件名称将失败。 PHP Fatal error: Uncaught PHPUnit\Framework\Exception: Class "Directory" does not extend PHPUnit\Framework\TestCase.
【解决方案2】:
  • 您可以使用类文档中的@group 标签来指示组,然后使用 --group 仅在该组上运行测试
  • 您可以使用 --filter 仅运行与给定正则表达式匹配的测试

2013 年更新

正如下面@havg 的回答所提到的,现在可以使用phpunit --testsuite 运行单独的测试套件

【讨论】:

  • 这很好用,如果测试套件不能单独运行,这可能是最好的选择。谢谢!
【解决方案3】:

你试过在命令行运行phpunit的时候添加路径作为参数吗?

类似

 phpUnit ./MyTestSuite1/

?

【讨论】:

  • 这确实有效,除非测试套件跨越多个不共享同一个根目录的目录。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-09
  • 2016-11-03
  • 2010-09-05
  • 2015-08-15
  • 2011-04-29
相关资源
最近更新 更多