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