如何通过phpunit.xml从测试套件中包括/排除某些组

Sam*_*ony 3 php phpunit unit-testing

我想从测试套件中排除或包括某些测试。我想通过注释/组对此进行一些控制,而不是在其中命名特定文件或文件夹phpunit.xml

我已经尝试过类似的操作,但是它似乎忽略了<groups>和/或<include>

<testsuites>
    <testsuite name="Unit">
        <directory>Unit</directory>
    </testsuite>
    <testsuite name="IntegrationFirstRound">
        <directory>Integration/</directory>
        <include><!-- I want to ONLY include this group -->
            <group>first-round</group>          
        </include>
    </testsuite>
    <testsuite name="IntegrationOther">
        <directory>Integration/</directory>
        <exclude><!-- I want to EXCLUDE this group, run all others -->
            <group>first-round</group>
        </exclude>
    </testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)

我不想将测试移到其他文件夹以适应此情况,并且我不想从CLI多次调用phpunit,我希望可以通过xml配置获得所需的结果。

Art*_*nix 7

好吧,看看DOC,它应该是您首先看到的地方

https://phpunit.de/manual/current/zh/appendixes.configuration.html

您需要一个groups包含其group内部的元素。所以你有

<exclude><!-- I want to EXCLUDE this group, run all others -->
     <group>first-round</group>
</exclude>
Run Code Online (Sandbox Code Playgroud)

你应该有

<groups>
    <exclude><!-- I want to EXCLUDE this group, run all others -->
        <group>first-round</group>
   </exclude>
</groups>
Run Code Online (Sandbox Code Playgroud)

它并没有真正说明它是否应该放在内<testsuite>,并且我从未使用过它,但是我敢肯定,如果您查看文档,将会发现一些示例。

  • 感谢您的回复。我已经尝试过你的建议(我的问题中输入错误)。我查看了文档并进行了实验。也许这不受支持。将“&lt;groups&gt;&lt;exclude&gt;&lt;group&gt;...”放在“&lt;phpunit&gt;”标签内确实有效,也许它们不属于“&lt;testsuite&gt;”标签内,文档并不具体。 (2认同)
  • 不支持在“&lt;testsuite&gt;”中使用“&lt;groups&gt;”。我只是尝试了一下,但没有成功。它将显示此错误:`元素'组':该元素不是预期的。预期是(目录、文件、排除)之一。` (2认同)

Bed*_*ang 6

就我而言,我分组为data


<?php

namespace Tests\Unit\Artefact;

use Tests\TestCase;

/**
 * @group data
 */
class DataMovieTest extends TestCase
{

}
Run Code Online (Sandbox Code Playgroud)

然后从终端运行 phpunit 像

phpunit --exclude data

Run Code Online (Sandbox Code Playgroud)