When I run the same test of Feature test,it passes the test. But when I run the same test on Unit test, It gives me {InvalidArgumentException: Unable to locate factory for [App\Reply]}. Here is the My test
<?php
namespace Tests\Unit;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\TestCase;
class ReplyTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function a_reply_has_user()
{
$reply = factory("App\Reply")->create();
$this->assertInstanceOf("App\User",$reply->user);
}
}
Here is the Error
1) Tests\Unit\ReplyTest::a_reply_has_user
InvalidArgumentException: Unable to locate factory for [App\Reply].
Here is the factory for the Reply:
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Reply;
use Faker\Generator as Faker;
$factory->define(Reply::class, function (Faker $faker) {
return [
"user_id"=>factory("App\User")->create(),
"thread_id"=>factory("App\Thread")->create(),
"body"=>$faker->sentence
];
});
Aucun commentaire:
Enregistrer un commentaire