views:

110

answers:

2

Hi,

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

+7  A: 

@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.

Diadistis
Thank you very much for your answer. :)
boxoft
You're welcome.
Diadistis
+5  A: 

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).)*$/
Ivan Krechetov
Thank you very much for this alternative method. :)
boxoft
You are welcome!
Ivan Krechetov
You don't actually need to define it as a regex, a plain old string will also work.
garrow