如何使用 xml 配置从 phpunit 中排除多个文件?

How to exclude multiple files from phpunit using the xml config?

我的 xml 文件中有以下内容,但它没有跳过第二个文件:

<testsuites>
        <testsuite name="Application Test Suite">
            <directory>./app/tests/</directory>
            <exclude>./app/tests/unit/1.php</exclude>
            <exclude>./app/tests/unit/2.php</exclude>
        </testsuite>
    </testsuites>

我建议您使用 phpunit group annotation 标记 classes/methods 并将该组标记为从主测试套件中排除。 您可以阅读 this article 作为进一步的参考。

例如,您可以在测试中执行以下操作 class:

class 1 extends PHPUnit_Framework_TestCase
{
    /**
     * @group excludeMe
     */
    public function testSomething()
    {
    }

    public function testSomethingElseDoNotExclude()
    {
    }

 ...

}

并将您的组添加到 phpunit.xml 文件中排除,例如:

<phpunit 
 ....
>
   ....
    <groups>
        <exclude>
            <group>excludeMe</group>
        </exclude>
    </groups>
</phpunit>

有关 xml annotation reference 中的组的更多信息并搜索 <groups>

希望对您有所帮助