LoginSignup
4
1

More than 3 years have passed since last update.

LaravelでUnitテストだけ実行する

Posted at

結論、以下のようにしてtestスイートを指定してテストが実行できます。

php vender/bin/phpunit --testsuite Unit

説明

プロジェクトが大きくなってくるとテストも増えてきて、テストを実行するときに部分的に実行したくなると思います。

LaravelだとテストはデフォルトでUnitとFeatureの2つのテストの種類がありますが、このうち高速なUnitテストだけをより高頻度で実行したすることができたら便利ですよね。

Laravelには、デフォルトでphpunit.xmlにテストの設定が書かれていてUnitテストとFeatureテストはそれぞれ別々のtestスイートとして設定されています。

phpunit.xml
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>

これによりphpunitを実行するときに特定のtestスイートを指定するとその部分だけ実行できます。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1