How to Group Some PHPUnit Tests and Run Them Separately?

Run group of PHPUnit tests

You can group and run a select few PHPUnit tests together by using the @group annotation like so:

/**
 * @group foo
 */
public function testMethod()
{
    // ...
}

Once you have tagged all the tests you wish to group, you can use the following command to only run the tests within that group:

phpunit --group foo

You can also specify multiple @group annotations for any single method, for example, like so:

/**
 * @group foo
 * @group bar
 */
public function testMethod()
{
    // ...
}

You can also specify the @group annotation to the class itself. In that case, all test methods of that test class would be considered a part of that group.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.