33

Is it possible to specify which test suite to run from a configuration file via the command line test runner? For example, if I have the following xml configuration:

<phpunit ...>
    <testsuites>
        <testsuite name="My Test Suite 1">
            <directory>./MyTestSuite1/</directory>
        </testsuite>
        <testsuite name="My Test Suite 2">
            <directory>./MyTestSuite2/</directory>
        </testsuite>
    </testsuites>
    ...
</phpunit>

Can I have it run only "My Test Suite 1"?

rr.
  • 6,484
  • 9
  • 40
  • 48
  • 1
    I know you can individual tests from Testcase. Not sure about suites though. Try to do something like `phpunit Suitename Path/To/AllSuites.php` or other way round. Also, check `phpunit --help` and http://www.phpunit.de/manual/3.4/en/textui.html – Gordon Dec 02 '10 at 08:25

3 Answers3

55

It's phpunit --testsuite "My Test Suite 1"

havvg
  • 699
  • 1
  • 5
  • 4
  • 8
    the --testsuite flag does not exist until 3.7 – moranjk Oct 30 '12 at 19:17
  • Note that there are reserved keywords, for example using "directory" as the test suite name will fail. `PHP Fatal error: Uncaught PHPUnit\Framework\Exception: Class "Directory" does not extend PHPUnit\Framework\TestCase.` – COil Oct 18 '19 at 09:02
10
  • you can use the @group tag in the class documentation to indicate the group and then run tests only on that group using --group
  • you can use --filter to only run tests that match a given regex

Update 2013

As @havg's answer below mentions, it's now possible to run individual test suites using phpunit --testsuite

El Yobo
  • 14,823
  • 5
  • 60
  • 78
  • This works nicely and is probably the best bet if test suites cannot be run individually. Thanks! – rr. Dec 02 '10 at 16:42
1

Have you tried when you run phpunit from the command line to add a path as a parameter?

So something like

 phpUnit ./MyTestSuite1/

?

sanders
  • 10,794
  • 27
  • 85
  • 127
  • This does work unless a test suite spans multiple directories that do not share the same root. Thanks. – rr. Dec 02 '10 at 16:40