phpunitHow to group tests in PHPUnit?
PHPUnit provides a way to group tests into logical units. This can be done by using the @group
annotation. Tests can be grouped by feature, type, or any other criteria.
<?php
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
/**
* @group feature
*/
public function testFeatureA()
{
// ...
}
/**
* @group feature
*/
public function testFeatureB()
{
// ...
}
/**
* @group type
*/
public function testTypeA()
{
// ...
}
}
The @group
annotation can be used to group tests together. Tests can be grouped by feature, type, or any other criteria. Tests can then be run by group using the --group
option.
$ phpunit --group feature
The code above will run all tests with the @group feature
annotation.
Helpful links
More of Phpunit
- How to skip a PHPUnit test?
- How to run tests in parallel with PHPUnit?
- How to use hooks in PHPUnit?
- What are PHPUnit required extensions
- How to use the PHPUnit Framework TestCase?
- How to run PHPUnit in quiet mode?
- How to show warnings in PHPUnit?
- How to load fixtures with PHPUnit?
- How to use a listener with PHPUnit?
- How to stop PHPUnit on failure?
See more codes...