Speed up your test

I wasn't happy with the time it took to run my test suite for a project so I investigated two options and I was able to go from 51 seconds to 7 seconds which is a huge improvement.
Here are my findings:

Using SQLite in memory in stead of MySQL

If was wary of doing this since previously, I had some issues with incompatibilities, mainly with:

  1. casting: SQLite casts everything as strings unless defined in your casts.

  2. case insensitive: on my local setup SQLite is case insensitive and MySQL is not.

  3. incompatible SQL: I had issues with a full outer join that SQLite does not support as well as these other features

After fixing these issues, I updated my phpunit.xml file: (default it should come with these settings)

    <env name="DB_CONNECTION" value="SQLite"/>
    <env name="DB_DATABASE" value=":memory:"/>

I ran my 210 tests (with 914 assertions) again:
with MySQL = 51s 180
with SQLite in memory = 34s 901ms

From 51 seconds to 34 seconds. Not bad!

Using parallel testing

Laravel now supports parallel testing. If you have installed the required composer package (brianium/paratest), you can add the option --parallel.
This required much less work but, of course, you will only gain speed if you run multiple tests (and it depends on the CPU cores that are available).

    php artisan test --parallel

I ran my tests again. This time, it only took 7 seconds and 320 milliseconds. Impressive!