Back to listSpring Boot • 8 min read

Integration tests that don't lie

TestContainers strategies to keep CI/CD fast without losing confidence in your code.

Author: Danilo FernandoPublished on January 18, 2025
Integration tests that don't lie

Green suites, fragile code

A green suite without confidence is worse than no suite — it gives you license to ship while the system burns.

The pattern that works

  1. TestContainers for real dependencies (Postgres, Kafka, Redis).
  2. Deterministic fixtures — no @Sql + random.
  3. One seed per test, no shared state.
  4. Assert on data, not on mock invocation counts.
@Testcontainers
@SpringBootTest
class OrderConfirmationIT {
    @Container
    static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:16")
        .withInitScript("db/init.sql");

    @DynamicPropertySource
    static void props(DynamicPropertyRegistry reg) {
        reg.add("spring.datasource.url", db::getJdbcUrl);
    }
}

What that buys

  • Tests that turn green with the code, not after.
  • Fearless refactors.
  • Objective conversations at code review.
#testing #spring-boot #testcontainers