How to speed up your tests in one simple step
Every tester with Continuous Improvement mindset cares about overall test execution time. We aim for quick feedback loops ending before developer switches to another task. This is not always easy as projects becomes bigger and bigger, teams focus on delivering new features and other issues receive higher priority.
Today I’d like to present you a very simple way of speeding up your tests. Most of the times we try to introduce test parallelism on code level. Unfortunately that’s usually very costly and hard to implement. Often we end up with complicated code that resolves our timing problems, but introduces new issues (increased code maintenance costs, flaky tests, timing problems, random test dependencies).
Idea is very simple. We spawn multiple test environment instances (ideally using lightweight Dockers) and execute only arbitrary percent of full test suite. In my example I split the tests by name. First suite execute tests matched by [a-m]* pattern and the second suite is running tests matched by [n-z]* pattern. This should theoretically create split close to 50-50.
To those unfamiliar with Gitlab CI few words of explanation. This is YAML file that stores our Continuous Integration job definition. First line (image) defines Docker container which will be pulled from Docker registry at the beginning. We get official maven image which guarantees us that mvn command is working properly. Next the application code is downloaded inside a container and scipt starts.
We split the tasks into two stages. First stage (build) contains only one job: execute ‘mvn -U -B clean compile’ command. Remember that we want to detect failures as soon as possible, so compilation is our first quality gate.
If first stage succeeds we move into phase two (test). This time though tasks start simultaneously. Two set of tests ( matched by regex) are executed on the same time.
This time we have only one stage (test). Each one use mocha to run ~50% of tests present in server-test folder.
This simple trick shortens overall test execution time and provides us with faster feedback. Please note that this solution is also scalable (by adding new Docker and splitting test suite into more separate chunks).
Tags: CI/CD, testing tools