How to execute choice of test cases from multiple test cases

user808548 picture user808548 · Jul 1, 2011 · Viewed 11.2k times · Source

I want to execute few selected test cases from my class of multiple test cases using php unit with ease.

As my 1-2 test cases are failing from bunch of test cases and also finding difficult to execute whole test suite again for these two, is there any method without adding comment to the others or copying these two methods in different suite.

Thanks to all in advance

Answer

edorian picture edorian · Jul 1, 2011

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
<?php

class 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