How and why you need to speed up tests
Описание и применение
Избыточное количество тестов приводит к нехватке ресурсов и долгим запускам, замедляя разработку. Применение стратегий сокращения тестов, использования хостовой БД, транзакционного отката и отключения триггеров ускоряет выполнение и повышает эффективность.
Задача
An excessive number of tests caused resource exhaustion and long test runtimes, slowing development.
Результат
Adopting these practices reduced test execution time, mitigated resource exhaustion, and accelerated development cycles.
Рабочий процесс
- 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.
Доказательства
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.
- Дата записи: 2026-11-03T20:28:46.505Z