Organizing Tests

Laravel Test PHPUnit Organizing Tests

Directory

<phpunit bootstrap="src/autoload.php">
  <testsuites>
    <testsuite name="money">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>
phpunit --bootstrap src/autoload.php --testsuite money

File

<phpunit bootstrap="src/autoload.php">
  <testsuites>
    <testsuite name="money">
      <file>tests/IntlFormatterTest.php</file>
      <file>tests/MoneyTest.php</file>
      <file>tests/CurrencyTest.php</file>
    </testsuite>
  </testsuites>
</phpunit>

Group

<testsuites>
    <testsuite name="include_exclude_groups">
        <group>first</group>
        <exclude>second</exclude>
    </testsuite>
</testsuites>
<testsuites>
    <testsuite name="specific_order">
        <group>first</group>
        <file>tests/second/second_test.php</file>
        <file>tests/second/third_test.php</file>
    </testsuite>
</testsuites>

Mix the file & directory test

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>
    <testsuites>
        <testsuite name="unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
        <testsuite name="money">
            <file>tests/first/first_test.php</file>
            <file>tests/second/second_test.php</file>
            <file>tests/first/third_test.php</file>
        </testsuite>
    </testsuites>
</phpunit>

Reference