In my phpunit.xml
I have a number of <testsuite>
's defined each of which defines a different aspect of my application to test. During development I don't want to necessarily run every test suite, only the ones in the aspect I'm working on.
However, when I want to test my full application I'd like to specify multiple test suites to run. Is there a way to do this from the command line?
With the lastest versions of PHPUnit (since v6.1) you can simply separate suites with a comma (--testsuite <name,...>
).
Examle: phpunit --testdox --testsuite Users,Articles
Documentation: https://phpunit.readthedocs.io/en/8.0/textui.html?highlight=--testsuite#command-line-options
You can use the @group
annotation to do this. Here are the docs for annotations in phpUnit.
You specify the group a test belongs to by putting @group examplegroup
in the php docblock above each test class you'd like to be in the group.
For example:
<?php
/**
* @group examplegroup
*
*/
class StackTest extends PHPUnit_Framework_TestCase
{
public function testPushAndPop()
{
$stack = array();
$this->assertEquals(0, count($stack));
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));
$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
}
?>
Running the group from the command line works as follows:
phpunit --group examplegroup
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With