Help me with testing

Posted 4 months 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.