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配置获得所需的结果。
好吧,看看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>,并且我从未使用过它,但是我敢肯定,如果您查看文档,将会发现一些示例。
就我而言,我分组为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)
| 归档时间: |
|
| 查看次数: |
1477 次 |
| 最近记录: |