Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run multiple phpunit.xml files?

Tags:

xml

phpunit

I have a project that is broken down into the following:

ProjectName/
  ModuleOne/
  ModuleTwo/

each module has a phpunit.xml and a test directory. Each module also has their own composer.json and so on and so forth, allowing me to easily package this as one library or allow you to get specific modules based on your needs.

The issue I have is that since each module has its own test folder with a phpunit.xml file, I need to create another phpunit.xml at the root of the project that runs each modules tests. I thought I could do this via:

<testsuites>
  <testsuite name="ModuleOne">
    <directory>ModuleOne/tests/</directory>
  </testsuite>
  <testsuite name="Moduletwo">
    <directory>Moduletwo/tests/</directory>
  </testsuite>
</testsuites>

But when I run phpunit from the root directory I get a message saying no tests were run. Why? I specified the test suite name and the directory of where the tests live...

Is there something I am missing?

like image 652
TheWebs Avatar asked Jun 04 '26 04:06

TheWebs


1 Answers

Unfortunately PHPUnit automatically applies phpunit.xml or phpunit.xml.dist only in the current working directory (see documentation for --configuration here).

There may be a way to set PHPUnit options dynamically from the test itself, or you can try using custom test suite loader or result printer. But I'd suggest just running PHPUnit two times and then combining the results if needed.

like image 196
Eugene C Avatar answered Jun 08 '26 01:06

Eugene C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!