Tests take too long: how to speed up a regression suite
Updated:
A regression suite repeatedly checks that a change has not damaged features that worked before. If its result arrives too late, a developer may stop waiting for it and the team may move the tests to a nightly run. The aim is to deliver a result while it can still influence a decision about the change or release.
Where time is most often lost
Too many checks run through the user interface. Every test opens a browser, signs in and moves through screens even though it verifies only one combination of rules.
Tests run only in sequence. Independent scenarios wait for one another because they share an account, data or an environment.
The suite contains fixed pauses and retries. Short waits add up across hundreds of steps. An unstable test also consumes time on its second or third attempt.
Environment preparation is repeated. Installing dependencies, building the application or creating the same data may take longer than the check itself.
Everything runs for every change. A quick check of a critical feature waits for scenarios that are relevant only to another part of the product.
Separate the components of elapsed time first
Measure not only the total pipeline duration but also queue time, environment preparation, individual tests and retries. Track the median as well as slower runs because the average can hide an occasional large variation.
The result should be a list of the largest contributors. If environment setup consumes most of the time, parallelising tests will not help much. If several tests wait for an external service, a faster machine will not solve the cause.
How to speed up the suite
Move each check to the appropriate layer
Combinations of calculations, permissions and error states often belong in unit or API tests. Keep representative user journeys in the browser. The test pyramid explains this balance, while our comparison of API and UI tests shows it in practice.
Prepare tests for concurrent execution
Every test needs its own data and independent state. When tests do not overwrite the same user or order, they can be distributed among several workers. Match the number of workers to the application’s and infrastructure’s capacity. Excessive concurrency can overload the environment and make results worse.
Replace waits for time with waits for state
A test should continue as soon as the expected operation is complete, not after a fixed number of seconds. Also track tests that pass only on a retry. Stabilising them often shortens the suite without changing its coverage.
Split feedback by purpose
A small set of critical checks can run for every relevant change. A broader suite can follow before a release or on a schedule. This split must not mean that important tests are pushed to a nightly run without an owner. Every layer needs a defined response to failure.
Remove duplicates and invalid scenarios
A test that checks a discontinued feature or exactly duplicates another check adds to both execution and maintenance time. Confirm its purpose with the product owner before retiring it, and document the reason.
Find the longest path to the result
The sum of test durations is not the wait for a report when parts run concurrently. In a model pipeline, shared queueing takes 5 minutes and setup takes 8. Four parts then start together and take 6, 8, 9 and 18 minutes. Merging reports requires another 2 minutes. The result arrives after 33 minutes, rather than the sum of every test execution time.
If you shorten the longest part to 10 minutes while preserving assertions and leaving other phases unchanged, the result arrives after 25 minutes. Further accelerating the shortest part does not reduce total elapsed time. These numbers model a calculation, rather than report a measured customer result. In real CI, include different job start times, each job’s setup and waiting for available machines too.
Balance work and verify independence
Playwright Test divides a suite into shards, separate parts for CI jobs. Without fullyParallel, distribution is based on files. With fullyParallel, it uses individual tests. Equal test counts do not guarantee equal duration. Check whether one machine is processing a long file at the end while the others wait.
In Python, pytest-xdist can provide concurrency. Its distribution by files, classes or groups is different from Playwright Test settings. Grouping can reduce repeated expensive setup but also create a long indivisible part. Choose according to measurements and data dependencies.
After changing worker counts, inspect runner CPU and memory as well as application response times. With multiple jobs, verify globally unique accounts and data identifiers. A local worker number may not be unique across machines. If concurrency exposes an order dependency, fix setup first. Removing assertions or increasing retries does not address that cause.
Accelerate setup without sharing unknown state
A built artefact can be prepared once and passed to jobs using the same version. Measure cache restoration too, and verify that its key distinguishes relevant versions and environments. Playwright does not recommend automatically caching browser binaries, because restoration may take about as long as downloading. Required operating-system dependencies may still be missing.
Do not confuse a shared dependency cache with a shared basket, authentication session or record that tests modify. Data needs known setup even after a cancelled run. When moving a check from UI to API, separately confirm which user step remains covered in the browser. A faster price calculation does not establish that the correct price is shown to the customer.
Accept acceleration against the same coverage
Compare the same builds or explicitly declared changes, data, browsers and scenarios. Track first attempts, retries, slow runs and CI resource consumption. Playwright Test can classify success after a retry as flaky. A shorter green report after skipping a troublesome test does not demonstrate acceleration with unchanged coverage.
If selecting tests by changed files, include shared libraries, configuration and dependent features too. Regularly compare the selection with a full run and record what remained unverified for a particular change. Define a maximum duration, diagnostics when it is exceeded and the owner’s response. A disabled check must remain visible in the release decision.
What to watch out for
Adding a faster machine or more workers can merely hide inefficient architecture. It is equally risky to gain speed by disabling checks without assessing the consequences. After every change, compare not only time but also stability and retained coverage of critical journeys.
What you gain
- A shorter run can reduce team waiting time and deliver a result while developers and the release process can still respond to it.
- The effect on infrastructure costs depends on the approach. Greater concurrency can also increase consumption.
- Concurrent, isolated tests provide more predictable feedback.
- Measurement reveals which further improvement has the greatest value.
Next step
Divide the latest run into queueing, preparation, test execution and retries, then identify the three largest contributors. If you want a plan for reducing the duration without losing important coverage, contact us. We will propose an order of changes and a metric that can verify the result.