Improve Symfony Tests Performance


Articles
Anglais
Gratuit
Non renseigné
Tests

Merci à Cyril T. pour sa contribution le 22/11/2021


Connectez-vous

Description :


Improve Symfony Tests Performance

November 21, 2021 • Edit this Post
php symfony tests

Using more simple password hashers
Do not use Doctrine logging by default
Set APP_DEBUG to false
Completely disable Xdebug
Parallel tests execution using Paratest
Collect coverage with pcov if possible
Collect coverage with cacheDirectory
Miscellaneous
Use dama/doctrine-test-bundle to rollback transaction after each test
Combine functional & unit tests. Prefer Unit tests

For all the latest Symfony projects at my company we were writing unit and mostly functional tests, occasionally improving their performance, but didn't have a chance to summarize all the improvements we made to speed up the test suite.

In this article, I will show the most comprehensive list of tips and tricks to decrease tests time, resource consumption and improve their speed.

First, let's start with our baseline for one of the projects.

2285 - the total number of tests
979 unit tests
1306 functional tests (Symfony's WebTestCase, testing API endpoints)
Symfony 5.3, PHP 8.1

The whole test suite before optimizations takes: Time: 12:25.512, Memory: 551.01 MB.

Why having a fast and reliable tests suite is important? There a lot of reasons, but 2 main are:

The more tests suite takes to be executed, the more annoying it is for a developer
The more resources (CPU, Memory) tests suite takes, the worse it is for CI server (it can slow down other jobs/builds) and eventually for our Planet

Let's see what we can do here.