Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TheUsernameHasAlreadyBeenTaken's avatar

Parallel testing with a single database?

We have a legacy application that can't use seeding (and it would take forever to seed it properly anyway). We have thousands of tests and it takes a long time to run them.

All tests are using the DatabaseTransactions trait.

Is is possible to run tests in parallel? Like 8 or more threads.

0 likes
3 replies
JussiMannisto's avatar

Yes. Use the --parallel option with --processes:

php artisan test --parallel --processes=8

Each process creates its own test database.

Edit. You need the brianium/paratest package for parallel tests:

composer require brianium/paratest --dev
TheUsernameHasAlreadyBeenTaken's avatar

The whole point of my thread is that I can't do that because the database already exists and I can't seed/create new ones. I need to run all tests in transactions in the already existing single database.

JussiMannisto's avatar

Test databases persist once they've been created, so they can be reused between tests. You'd only need to seed them once, e.g. by importing a dump of the existing test database. Is that not an option?

If every process ran simultaneous transactions in the same database, you'd get a lot of lock contention.

Please or to participate in this conversation.