phpunitHow to order tests with PHPUnit?
PHPUnit provides a way to order tests using the @depends
annotation. This annotation allows you to specify that a test method depends on another test method. The dependent test method will be run before the test method that depends on it.
For example:
class MyTest extends TestCase
{
public function testA()
{
// ...
}
/**
* @depends testA
*/
public function testB()
{
// ...
}
}
The @depends
annotation can also be used to specify multiple test methods that the current test method depends on.
For example:
class MyTest extends TestCase
{
public function testA()
{
// ...
}
public function testB()
{
// ...
}
/**
* @depends testA
* @depends testB
*/
public function testC()
{
// ...
}
}
In this example, testC
will be run after both testA
and testB
have been run.
Helpful links
More of Phpunit
- How to test private methods in PHPUnit?
- How to show warnings in PHPUnit?
- How to run tests in parallel with PHPUnit?
- How to clear the PHPUnit cache?
- How to log to the console with PHPUnit?
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- How to disable deprecation notices in PHPUnit?
- How to run all PHPUnit tests?
- What are PHPUnit required extensions
See more codes...