When building a test framework, it is important to keep in mind certain criteria. This would help to make it more effective, scalable and fast. And test parallelization is one of the most important criteria to make your tests run faster.

Your goal is to run several tests in parallel, so that the whole test set will be executed several times faster in comparison when all tests run sequentially, one after the other. For example, if you set test parallelization to 5, it means that the total test execution time may be reduced by 5 times. That is, if your e2e tests now run sequentially and take e.g. 50 minutes, after parallelization will take only 10 minutes. It is a significant achievement.

Why is fast test execution so important? There are different cases.

One case is if you often release to Production during the day. You will then benefit from the fast regression test cycles: for example, in 10 minutes you can say if the current version of your application is ready for release. The more frequently you deploy to Production the more important fast test execution would be.

In another case, a project team releases once a sprint, that is once in one - two weeks. There is no such urgency. Then running automated regression tests at night would be sufficient during the sprint, and one final test run during the release day. And you may think that those tests running every night can potentially take longer time, e.g. 2 hours. It seems like not a big deal because anyway you will check test results only in the morning. But from the other point of view, you will still want faster tests. Why? Because imagine a situation when the tests fail overnight, maybe due to a problem in the environment. Then in the morning, you will want to rerun the tests ASAP, once the configuration issue is fixed. And here faster test runs would be, of course, beneficial.

So, you should have a goal to reduce test execution time by any possible means, of course, without losing the quality of the tests.

Enabling test parallelization differs in different test frameworks/libraries and languages. But the principle is the same, and it may look like this:

Here we see the level of parallelism, 5, which means 5 tests will run in parallel. The scope of parallelism is also important: in this case above, all tests in all feature files or classes will run in parallel. If the scope is smaller, then tests, for example, only in different classes/feature files will run in parallel, but within the same class/feature file will run sequentially. In such a case, tests will take longer to execute, but still, it is better then sequential test execution.

When configuring test parallelization, there are several areas in the test framework to pay attention to.

For UI tests, which open the browser (if we talk about web apps), you need to ensure that there is no conflict between the browser instances. For example, if each test opens a browser session and then closes, then we need to ensure that the right browser session is closed by the right test. Otherwise, a test may fail because its browser session has been closed by another test.

For both UI e2e and API integration tests, conflicts may occur when some tests interact with the same data. For example, your application might have some general settings data. Your tests change the settings and check how it is reflected in other functionality. When running such tests in parallel, it is very likely the data changes will be conflicting and tests will fail. To avoid this problem, you need to run the tests sequentially. One of the common and easiest mechanisms to force specific tests run sequentially is via tags, which you write above such tests. It may look like this:

Among the reasons to run certain tests sequentially may also be some “heavy” transactions. For example, generating a big report or importing a big XML file. If your test environment is not very powerful, then running several parallel tests with such heavy transactions may lead to test failures because your app simply can’t cope with the load.

There are other aspects in test parallelization, and we will try to cover them later. But for now, we have looked at some most common and important ideas in this topic.