0
0

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 1 year has passed since last update.

laravel Factoryを用いてテストデータを作成する(使用編)

Posted at

概要

  • laravelにてFactoryを用いてテストデータを作成する方法をまとめる。

前提

方法

  1. Featureテストクラスを用意する。

  2. setUp()関数に下記の様に記載してFactoryを用いてデータをテーブルに格納する。

    FooTest.php
    public function setUp(): void
    {
        parent::setUp();
    
        モデルクラス::factory()->createOne();
    }
    
  3. 紐づくテーブルにFactoryを用いて1件のレコードが追加される。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?