How to execute choice of test cases from multiple test cases
You may run single test cases or single test classes from your suites using the --filter cli option:
--filter <pattern> Filter which tests to run.
--filter
runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names.
Example
Take the following example test class BlaTest
containing test cases testSame
and testElse
in file BlaTest.php
:
// BlaTest.php<?phpclass BlaTest extends PHPUnit_Framework_TestCase { public function testSame() { $this->assertSame(1,1); } public function testElse() { $this->assertSame(1,1); }}
Running all test cases within BlaTest
This filter matches the test class name.
$ phpunit --filter BlaTest
Running a single test case within BlaTest
This filter matches the test case name, then indicates to run this filter across file BlaTest.php.
$ phpunit --filter testSame BlaTest.php
--filter
option accepts regular expression as its value (I'm using phpunit 3.7). This lets you specify the tests which will be excluded by using assertion like following: --filter='/::((?!test(Else|Same))\w+)/'
If you prefer to filter code-wise you could mark the test to be skipped within the setUp()-method [1] by checking which test is about to be run using $this->getName(). That way these tests will show up as being skipped.
An example:
class FooTest extends PHPUnit_Framework_TestCase { public function setUp() { if( 'testIwantToSkip' === $this->getName() ) { $this->markTestSkipped( 'Test skipped!' ); } } ...}