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 show warnings in PHPUnit?
- How to skip a PHPUnit test?
- How to install PHPUnit with a PHAR file?
- How to install PHPUnit from Packagist?
- How to mock a method with different arguments in PHPUnit?
- What are PHPUnit required extensions
- How to run only certain methods in PHPUnit?
- How to increase memory limit in PHPUnit?
- How to mock a class in PHPUnit?
- How to mock a static method with PHPUnit?
See more codes...