almokhtar_br
1 year ago

Help me with testing

Posted 1 year ago by almokhtar_br

Hi , guys i'm new in phpunit : this is error take a day from me i wish someone have a solution

Time: 226 ms, Memory: 16.00MB

There was 1 error:

1) Tests\Feature\PostTest::test_show_all_posts
InvalidArgumentException: Unable to locate factory with name [default] [App\Post].

/Volumes/HHD/dev/laravel/udemy_clone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:258
/Volumes/HHD/dev/laravel/udemy_clone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:281
/Volumes/HHD/dev/laravel/udemy_clone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php:122
/Volumes/HHD/dev/laravel/udemy_clone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:289
/Volumes/HHD/dev/laravel/udemy_clone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:208
/Volumes/HHD/dev/laravel/udemy_clone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:167
/Volumes/HHD/dev/laravel/udemy_clone/tests/Feature/PostTest.php:32

ERRORS!
Tests: 3, Assertions: 6, Errors: 1.

this is my code :

        public function test_show_all_posts(){
            
            // arrangement
                $p1 = factory(Post::class)->create();
                $p2 = factory(Post::class)->create();
            // action
                $resp = $this->get('/posts');
            // assert
                $resp->assertStatus(200);
                $resp->assertSee($p1->title);
                $resp->assertSee($p2->title);
        }


Please sign in or create an account to participate in this conversation.