I would like to exclude or include certain test from test-suites. I would like to have some control of this via annotations/groups rather than naming specific files or folders in phpunit.xml
I have attempted something like this, but its appears to be ignoring the <groups>
and/or <include>
<testsuites>
<testsuite name="Unit">
<directory>Unit</directory>
</testsuite>
<testsuite name="IntegrationFirstRound">
<directory>Integration/</directory>
<include><!-- I want to ONLY include this group -->
<group>first-round</group>
</include>
</testsuite>
<testsuite name="IntegrationOther">
<directory>Integration/</directory>
<exclude><!-- I want to EXCLUDE this group, run all others -->
<group>first-round</group>
</exclude>
</testsuite>
</testsuites>
I don't want to move tests to different folders just to accommodate this, and I do not want to invoke phpunit multiple times from the CLI, I am hoping I can achieve the desired results via the xml config.
The <testsuites> Element This element is the root for one or more <testsuite> elements that are used to configure the tests that are to be executed.
PHPUnit uses XML file for configuration. This configuration file can be added to your version control system so all developers get the same output. These settings will help you make sure your tests work the way you want.
You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status. The output shows that we ran 1 test, and made 3 assertions in it.
PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. PHPUnit 9 is the current stable version. PHPUnit 10 is currently in development.
Ok, looking at the DOCs which should be the first place you look
https://phpunit.de/manual/current/en/appendixes.configuration.html
You need a groups
element with the group
inside of it. So where you have
<exclude><!-- I want to EXCLUDE this group, run all others -->
<group>first-round</group>
</exclude>
You should have
<groups>
<exclude><!-- I want to EXCLUDE this group, run all others -->
<group>first-round</group>
</exclude>
</groups>
It doesn't really say if it should go inside the <testsuite>
, and I never used it but I am sure if you look in the documentation you should find some examples.
In my case I grouped as data
<?php
namespace Tests\Unit\Artefact;
use Tests\TestCase;
/**
* @group data
*/
class DataMovieTest extends TestCase
{
}
and then run phpunit from terminal like
phpunit --exclude data
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