运行匹配多个组的测试

myo*_*yol 3 phpunit

我有各种类型的测试(单位,验收等),我为粒度分配了多个标签

/**
 * @test
 * @group unit
 * @group controllers
 */


/**
 * @test
 * @group unit
 */


/**
 * @test
 * @group controllers
 */
Run Code Online (Sandbox Code Playgroud)

是否可以运行匹配两个或更多组的phpunit测试?就像是

--group unit|controllers
Run Code Online (Sandbox Code Playgroud)

在这种情况下,应该运行的唯一测试将是第一个测试,因为它同时具有unitcontrollers组,而其他测试不会运行.

使用符号

--group unit,controllers
Run Code Online (Sandbox Code Playgroud)

运行所有测试unit,然后是所有(或剩下 - 我不太记得)测试controllers- 在大型项目中,这可能导致长时间运行.

Seb*_*ann 10

  • --group unit,controllers 应该管用
  • --exclude 还存在运行除指定组中的测试之外的所有测试
  • @group unit|controllers 不是允许的语法


小智 5

您需要重新考虑@group注释的使用,从拆分到测试套件开始。您可以尝试遵循有关文件结构的 phpunit 规则或使用 xml 定义测试套件。例如:

<phpunit bootstrap="src/autoload.php">
  <testsuites>
    <testsuite name="unit">
      <directory>webroot/*/Tests/Unit</directory>
    </testsuite>
    <testsuite name="integration">
      <directory>webroot/*/Tests/Integration</directory>
    </testsuite>

    <testsuite name="controllers">
      <directory>webroot/*/Tests/Integration/Controller</directory>
    </testsuite>

  </testsuites>
</phpunit>
Run Code Online (Sandbox Code Playgroud)

@groups通常用于按业务实体进行组合,例如。运行与应用程序的搜索功能相关的所有测试。

更多信息请参见https://phpunit.de/manual/current/en/organizing-tests.html