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 stop PHPUnit on failure?
- How to use PHPUnit json assert?
- How to show warnings in PHPUnit?
- How to skip a PHPUnit test?
- What are PHPUnit required extensions
- How to use named arguments in PHPUnit?
- How to disable color output in PHPUnit?
- How to increase memory limit in PHPUnit?
- How to launch one test with PHPUnit?
- How to run all PHPUnit tests?
See more codes...