Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Zalando Engineering 9 min read How-to mediumAdept

Mastering Testing Efficiency in Spring Boot: Optimization Strategies and Best Practices

Spring Boot test suites can be sped up substantially by loading less of the application context and reusing what is loaded. Test slices (@DataJpaTest, @JsonTest, @WebMvcTest) replace full @SpringBootTest contexts, with worked fixes for common pitfalls: disabling H2 replacement via @AutoConfigureTestDatabase, importing needed beans, and using REQUIRES_NEW transactions so multithreaded tests see committed data. Consolidating @MockBean declarations into a shared base class or @TestConfiguration keeps the context cache key stable, @DirtiesContext should be avoided, and JUnit 5 parallel execution adds further gains. Together these cut Zalando's CI test time from about 10 minutes to 4m15s, roughly 60% faster.

Related posts

  • Functional tests with Testcontainers

    Zalando Engineering mediumAdept

    Black-box functional tests for a Spring service can run against the service packaged as a Docker image, with PostgreSQL and other dependencies started as separate containers via Testcontainers. The setup uses a Maven multi-module layout where the functional-tests module has no dependency on service code. Tests talk to the service only through plain JSON over its public REST API, and a shared abstract base class starts containers once with health-check waits, log consumers, a remote debug port and a shutdown hook as a backstop to Ryuk. The approach gives strong confidence during deep refactoring and also verifies the Docker packaging. Its costs are slow container startup (about 4s for Postgres, up to 20s for Localstack), harder debugging, and the need to isolate test data because containers are shared across tests.

  • Mobile Developer Experience at Slack

    Slack Engineering mediumAdept

    A dedicated mobile Developer Experience team grew from 3 to 8 engineers and cut CI feedback time and failure rates by targeting the pain points that surveys, NPS and metrics like time to merge showed hurt developers most. iOS test time fell from about 50 minutes to an average of 9 by moving from Xcodebuild to Bazel with disk caching and bazel-diff, so only affected targets are tested. On Android, test sharding (in-house Fuel, later Flank) cut runs from 50+ minutes to under 20, and replacing Calabash with Espresso took suites from ~350 to ~60 minutes. Further gains came from auto-suppressing flaky tests (failure rate 57% to 4%), migrating from Jenkins to Buildkite (CI stability ~87% to 95%, TTM down 41%), generating Xcode projects with Xcodegen to avoid merge conflicts, and adopting a merge queue.

  • Bun v0.6.4

    Bun mediumAdept

    Bun v0.6.4 makes `bun test` up to 80% faster on suites with many small files by no longer forcing a synchronous garbage collection after every file, at the cost of roughly 9% more memory. The test runner now sets NODE_ENV=test, loads `.env.test` files, supports per-test and `--timeout` timeouts, adds `toHaveLength()`/`toBeEmpty()` matchers, and defaults to the Etc/UTC timezone to reduce flaky CI tests. Other changes include `process.env.TZ` support, `require.cache` (which also works for ESM), JSX runtime and Node.js http/https compatibility fixes, and internal builtins rewritten in TypeScript that shrink the binary by about 900 KB.

  • The quest for the five minute deploy

    incident.io mediumAdept

    incident.io cut CI/CD times by moving from a hosted provider, where a cold Go build cache made compiling 15,000+ tests across 350+ packages the bottleneck, to Buildkite running on three self-hosted 48-vCPU servers. Prebuilding Ginkgo test binaries and running them in batches on a single server, plus per-server Go build caches, per-yarn.lock Node module caches with pipeline fallback, and local Docker image caches, brought the test step to 2–4 minutes. Production deploys fell from 11.5 to 8.5 minutes, branch builds from 10 to 5.5, and hotfixes to 3.5. Remaining pain points include bin packing containers, under-provisioned disk IOPS, newly exposed flaky tests, cache poisoning, zombie containers, and a fast-growing cache that must be cleared wholesale.

  • Leveraging Testcontainers for Complex Integration Testing in Mattermost Plugins

    Docker mediumAdept

    Mattermost replaced brittle mock-based plugin tests with Testcontainers-driven integration tests that spin up a Mattermost server, PostgreSQL on an internal Docker network, and optional API mock containers. A custom Go module exposes helpers for plugin installation, DB access, the Go API client and admin operations, while Testcontainers for Node.js pairs with Playwright for UI-level tests. The approach is used for the AI Copilot plugin (mocked LLM API) and the MS Teams plugin (mocked Microsoft Graph), giving isolated, repeatable tests where teams choose per-test or shared container lifetimes.

The quest for software engineering knowledge.

Look:
Layout: