如何从命令行 运行 多个 PHPUnit 测试套件?

How to run multiple PHPUnit test suites from command line?

如果您在 phpunit.xml 中配置了多个测试套件,您如何从命令行 运行 多个测试套件但不是所有测试套件?

phpunit.xml

<?xml version="1.0" encoding="utf-8"?>
<phpunit
    backupGlobals="false"
    backupStaticAttributes="false"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="true"
    syntaxCheck="true"
    bootstrap="tests/bootstrap.php">
        <testsuites>
            <testsuite name="Unit">
                <directory suffix="Test.php">tests/unit</directory>
            </testsuite>
            <testsuite name="Integration">
                <directory suffix="Test.php">tests/integration</directory>
            </testsuite>
            <testsuite name="Acceptance">
                <directory suffix="Test.php">tests/acceptance</directory>
            </testsuite>
        </testsuites>
        <logging>
            <log type="coverage-html" target="build/coverage"/>
            <log type="testdox-html" target="build/requirements.html"/>
        </logging>
        <filter>
            <whitelist>
                <directory suffix=".php">src</directory>
            </whitelist>
        </filter>
</phpunit>

例子

phpunit --testsuite Unit|Integration 但不是 Acceptance

从 PHPUnit 6.0 开始,您可以指定逗号分隔的套件列表:

--testsuite suite1,suite2

< PHPUnit 6.0 版本的原始答案

它没有像您预期的那样工作,即(其中 <pattern> 不是实际模式):

--testsuite <pattern> Filter which testsuite to run.

您可以选择要 运行 的测试套件,但不能使用模式来过滤要 运行 的测试套件。

更好的描述是--testsuite <name> Which testsuite to run.

版本 6.0 中的问题报告 https://github.com/sebastianbergmann/phpunit/issues/2273, which was fixed