Box
Box

Reputation: 2502

Not run some tests in PHPUnit?

I don't want to run all the tests sometimes to save time. I know I can comment the tests. But this method isn't elegant. I'm wondering whether there is some simple way to do that.

All advice is appreciated.

Thanks for your time and best regards, Box He

Upvotes: 4

Views: 1160

Answers (2)

Ivan Krechetov
Ivan Krechetov

Reputation: 19220

phpunit command line test runner has --filter argument which is a regular expression to match the executed test case names.

Suppose, you need to exclude all the test cases, names of which contain "Foo". Then, use:

--filter /^(?:(?!Foo).)*$/

Upvotes: 12

Diadistis
Diadistis

Reputation: 12174

@group

A test can be tagged as belonging to one or more groups using the @group annotation like this

class MyTest extends PHPUnit_Framework_TestCase
{
    /**
     * @group specification
     */
    public function testSomething()
    {
    }

    /**
     * @group regresssion
     * @group bug2204
     */
    public function testSomethingElse()
    {
    }
}

Tests can be selected for execution based on groups using the --group and --exclude-group switches of the command-line test runner or using the respective directives of the XML configuration file.

Upvotes: 11

Related Questions