4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelでのUnitテストで1つのメソッドだけ実行する

Posted at
  • Windows 10
  • PHP 7.4.5
  • Laravel Framework 7.9.2

開発中(コード実装中)にUnitTestを使って試行錯誤している場面など、テストケース全部ではなく実装中のこのテストだけ実行したいなと思った時の対応方法となります。

実装中のテストケースに印(アノテーション)を付ける

**@group**アノテーションで実行中のメソッドに印をつける。
今回はtestingという名前にしました。

SampleUnitTest.php
    /**
     * @test
     * @group testing
     */
    public function create_success()
    {
        $response = $this->get('/api/card/create');
        $response->assertStatus(200);
    }

実行時にグループを指定する

php .\artisan test --group=testing

もしくは

.\vendor\bin\phpunit --group=testing 

実装が終わったらアノテーションを削除するのを忘れずに

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?