How to Run Laravel Database Seeder from PHPUnit Test setUp? How to Run Laravel Database Seeder from PHPUnit Test setUp? laravel laravel

How to Run Laravel Database Seeder from PHPUnit Test setUp?


The DatabaseSeeder can be instantiated on its own, and its call method is public.

All you need to do in your CourseTypesTest class would be

(new DatabaseSeeder())->call(TestDatabaseSeeder::class);

Or you can make use of Laravel's app helper as follow

app(DatabaseSeeder::class)->call(TestDatabaseSeeder::class);


Since version 5.8 you can do:

// Run the DatabaseSeeder...$this->seed();// Run a single seeder...$this->seed(OrderStatusesTableSeeder::class);

Take a look at the documentation


The problem is empty space in your --class argument. If you take close look at array '--class' => 'TestDatabaseSeeder ' there is space in the end ... this is the problem. Change it to '--class' => 'TestDatabaseSeeder' and it should work fine.