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 mock a method with different arguments in PHPUnit?
- How to run tests in parallel with PHPUnit?
- How to run all PHPUnit tests?
- How to run only certain methods in PHPUnit?
- How to mock a static method with PHPUnit?
- How to mock a query builder with PHPUnit?
- How to launch one test with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to use hooks in PHPUnit?
See more codes...