PHPUnit: how to run specific tests

There might be a need to run a specific test or a subset of tests. Either it is just debugging a broken test or a new method or organizing tests into a suite.

A simple way to do that would be via ––filter switch:
phpunit ––filter testSomething

Alternatively a test can be tagged as belonging to a group using the @group annotation like this:

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

Tests can be selected for execution based on groups using ––group switch:
phpunit ––group testGroup

An extra benefit of the @group annotation is that ––exclude-group switch also allows to ignore groups of tests.

No Comment

No comments yet

Leave a reply