Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Organizing tests into folders and running them

Is it possible in Laravel to run unit test based on the folder they're placed in?

Currently, the phpunit.xml specifies /tests as the root directory for unit testing:

...
<testsuites>
    <testsuite name="Application Test Suite">
        <directory>./app/tests/</directory>
    </testsuite>
</testsuites>
...

Test are ran via CLI with phpunit command. I would like to organize tests into subfolders, like this:

/tests

  • /unit
  • /integration

so I can run tests only from the specified subfolder like: phpunit integration.

I tried the above, however the framework assumes that "integration" is the name of a PHP file that doesn't exist.

How do I achieve my goal?

like image 205
lesssugar Avatar asked Nov 30 '22 00:11

lesssugar


1 Answers

This actually has nothing to do with Laravel. It's just PHPUnit.

You can define testsuites and execute them by name.

<testsuites>
    <testsuite name="unit">
        <directory>./app/tests/unit/</directory>
    </testsuite>
    <testsuite name="integration">
        <directory>./app/tests/integration/</directory>
    </testsuite>
</testsuites>

Then run phpunit --testsuite integration

like image 119
lukasgeiter Avatar answered Dec 05 '22 22:12

lukasgeiter