Ajvanho's avatar
Level 14

error unit test: Unable to locate factory

I use this factory in feauture test and it is working. What is the problem in unit testing?

  1. Tests\Unit\ReplyTest::it_has_body InvalidArgumentException: Unable to locate factory for [App\Reply].

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;


class ReplyTest extends TestCase
{

	use RefreshDatabase;

    /** @test */
    public function it_has_body()
    {
        $reply = factory('App\Reply')->create();

        $this->assertInstanceOf('App\User', $reply->owner);
    }
}
0 likes
1 reply
Tray2's avatar
Tray2
Best Answer
Level 74

Change

use PHPUnit\Framework\TestCase;

To

use Tests\TestCase;

I don't know why the unit tests no longer uses the "correct" TestCase. You can most likely find out why in the documentation.

1 like

Please or to participate in this conversation.