phpunitHow to use PHPUnit annotations?
PHPUnit annotations are used to provide additional information about the tests. They are written in the docblock of the test method and start with an @
symbol.
Example
/**
* @coversDefaultClass MyClass
* @covers ::myMethod
*/
public function testMyMethod()
{
// Test code
}
The example above will tell PHPUnit to test the MyClass
class and the myMethod
method.
The following annotations are available:
@covers
: Tells PHPUnit to test the specified class or method.@depends
: Tells PHPUnit to run the specified test before running the current test.@dataProvider
: Tells PHPUnit to use the specified data provider for the test.@expectedException
: Tells PHPUnit to expect the specified exception to be thrown.@group
: Tells PHPUnit to group the test with the specified group.
Helpful links
More of Phpunit
- How to show warnings in PHPUnit?
- How to generate a coverage report with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to stop PHPUnit on failure?
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- What are PHPUnit required extensions
- How to install PHPUnit with a PHAR file?
- How to run tests in parallel with PHPUnit?
- How to order tests with PHPUnit?
See more codes...