带有工厂的laravel单元测试无法找到名称为[default]的工厂

时间:2018-10-05 09:54:08

标签: laravel model phpunit factory

我试图在laravel单元测试中为我的一个模型创建工厂

use Illuminate\Support\Collection;
use phpDocumentor\Reflection\Types\Parent_;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\User;
use Illuminate\Auth;
use App\Role;
use App\AppName\HolidaysEmployees;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class TestApiCalls extends TestCase
{


    public function setUp()
    {
        parent::setUp();

        $this->user = factory(User::class)->create([
            'firstname' => 'RA',
            'lastname' => 'Tester',
            'password' => bcrypt('tester'),
            'email' => 'ra@tester.com'
        ]);

        $this->holidays = factory(HolidaysEmployees::class)->make();
    }

}

但是当我运行测试时,我却不断得到

InvalidArgumentException: Unable to locate factory with name [default] [App\MyName\HolidaysEmployees].

在这种情况下我该怎么办?

1 个答案:

答案 0 :(得分:0)

我发现了如何在线解决此问题:

更改

class TestApiCalls extends TestCase

class TestApiCalls extends \Tests\TestCase