If you work with Laravel and TDD, you certainly know how fast your test suite can grow and even take several minutes to run.
With the latest versions of Laravel there are a couple of things you can do to speed it up.
Reset your database status only when you need to
Laravel 8 and up include a new LazilyRefreshDatabase
trait, which can be used in place of RefreshDatabase
to only migrate and seed the database if the previous test changed it.
See this episode of Laracasts for further information.
Use parallel testing
Another thing you can do to improve the running time of your tests is running them in parallel instead of sequentially.
The paratest composer package will help you with that.
Just follow the instructions in the README to install and use it.
Quick tip: with parallel testing, every test will run on a different database. Make sure your database user is allowed to create and operate on each of them, setting his permissions accordingly :)
Do you have any other suggestion to share about improving the test running time?
Top comments (0)