how to run parallel test in laravel?

Issue

I have 15 feature tests in the project. this information of env.test:

DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=test_db
DB_USERNAME=test
DB_PASSWORD=123456

when I run my test as parallel using php artisan test --parallel i get with error:

1) Tests\Feature\Settlement\PublicSTest::testCreatePublicS
Illuminate\Database\QueryException: SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied to create database (SQL: create database "test_db_test_3" encoding "utf8")

how to fix this error?

Solution

As the documentation states, Laravel will create multiple databases to avoid the parallel processes colliding with each others data.

Add the privilege for the user to create databases, assuming this is an postgres database based on the error.

Access cli

psql test_db test

Command to execute

ALTER USER test CREATEDB;

Answered By – mrhn

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published