获取将使用 PHPUNIT 配置文件执行的测试列表

Get the list of test that are going to be executed with a PHPUNIT configuration file

我有一个简单的问题:

用命令

phpunit -c|--configuration <file>

可以指定一个包含多个 phpunit 配置的文件,例如(但不限于):

 <testsuites>
        <testsuite name="unit">
            <directory>path/to/directory/one</directory>
             <directory>path/to/directory/two</directory>
        </testsuite>
  </testsuites>

这将生成要执行的测试列表。

虽然我不完全了解 phpunit 的内部实现,但我想以某种方式检索此 'list'。

您可以使用您的测试套件和 运行 phpunit --configuration path/to/phpunit.xml --testsuite <name test suite> 配置 phpunit.xml。

  • 如果你 运行 phpunit 在 phpunit.xml --configuration path/to/phpunit.xml 不需要的文件夹中,你可以 运行 只是 phpunit --testsuite <name test suite>;
  • 如果你想要 运行 所有测试都是 运行 没有 --testsuite <name testsuite> 的 phpunit;和
  • 如果你想要 运行 只是文件,你可以在你的测试套件中配置或者 run phpunit path/to/Test.php

注意:phpunit 会查找后缀为“*Test.php”的文件。

有关详细信息,请查看:https://phpunit.de/manual/current/en/organizing-tests.html

回答我自己的问题:

如果您查看 PhpUnit 的内部结构,解析器组件与命令调用的运行器组件紧密耦合。

这种情况几乎不可能重用 xml 解析器,迫使您要么复制粘贴代码块,要么重新实现解析逻辑。

长话短说 PhpUnit xml 解析逻辑不可重用。

您可以通过 parent 的设置将所有测试标记为已跳过,从而按执行顺序获取所有测试的列表:

public function setUp()
{
    $this->markTestSkipped($this->toString());
}