Reputation: 21236
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?
Upvotes: 3
Views: 5626
Reputation: 9480
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
Upvotes: 4
Reputation: 174
If each of your test suites has a different namespace, you could filter what test are run by using the --filter
option.
For example: phpunit --filter '/Controller|Tools/'
All tests that have a namespace that matches the regex will be executed.
You have more examples in the phpunit options documentation.
Upvotes: 3
Reputation: 1358
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
Upvotes: 4