How and why you need to speed up tests
Description and use
An excessive number of tests caused resource exhaustion and long runtimes, slowing development. Implementing test reduction, host database usage, transaction rollback, and trigger disabling speeds up execution and improves efficiency.
Problem
An excessive number of tests caused resource exhaustion and long test runtimes, slowing development.
Outcome
Adopting these practices reduced test execution time, mitigated resource exhaustion, and accelerated development cycles.
Workflow
- Prohibit agents from writing tests for obvious changes (e.g., migration scripts, enum additions, dependency list changes).
- Prevent duplicate tests by combining similar checks into a single test and adding a test audit skill for agents.
- Raise application context only once for all tests to avoid repeated setup.
- Use host database instead of test containers to save Docker memory and startup time.
- Deploy database schema once for all tests and clean the database by rolling back transactions instead of deleting rows.
- Disable triggers before clearing tables to reduce test runtime.
- Run only tests affected by the current code changes during development.
- Adjust pipeline CPU core power‑saving mode to speed up tests.
Evidence
The tests started consuming too many resources. The test bench encountered: OOMError, memory exhaustion in the database, exhaustion of lock and database connection limits.
If in spring a full test run took 10–15 minutes, in autumn it slowed down to 45 minutes.
We save: on Docker memory (relevant for Macs), on the time it takes to start the test containers, and on the time spent recreating the database schema from scratch for each test.
Disable triggers before clearing the tables in the test database. For me, this reduced the time required to run all tests by 15 minutes.
- Record date: 2026-11-03T20:28:46.505Z