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 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...