Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple PHPUnit test suites from command line?

Tags:

phpunit

If you have multiple test suites configured in phpunit.xml how do you run more than one test suite but not all of them from the command line?

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>

example

phpunit --testsuite Unit|Integration but not Acceptance

like image 693
IntrovertedRoot Avatar asked Jul 08 '16 22:07

IntrovertedRoot


1 Answers

Since PHPUnit 6.0 you can specify a comma delimited list of suites:

--testsuite suite1,suite2

Original answer for versions < PHPUnit 6.0

It doesn't work as you expect it to i.e. (where <pattern> is not an actual pattern):

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

You can choose a test suite to run but you can't use a pattern to filter which ones to run.

A better description would be --testsuite <name> Which testsuite to run.

Issue report https://github.com/sebastianbergmann/phpunit/issues/2273, which was fixed in version 6.0.

like image 141
Gerard Roche Avatar answered Sep 24 '22 02:09

Gerard Roche