Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run multiple test suites with PHPUnit

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?

like image 842
Luke Avatar asked Sep 04 '25 02:09

Luke


2 Answers

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

like image 165
Fabien Sa Avatar answered Sep 07 '25 18:09

Fabien Sa


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

like image 38
Peter Avatar answered Sep 07 '25 18:09

Peter