Video in progress

Staff 🧪 Testing

The platform team proposes building a shared test library for all services. How do you evaluate it?

It's useful for repeated infrastructure code (Testcontainers setup, an auth token generator, Kafka test helpers), but putting domain fixtures and service-specific builders in a shared library ties the services to each other. The library should be small, versioned and optional.

📖 Answer

The benefit is clear: across 30 services the Postgres + Flyway + @ServiceConnection setup has been rewritten 30 times, each with its own bugs. The helper for sending a request with a JWT differs in every team. With one library, a new service gets full test infrastructure in a day.

The risks are real too:

  • Coupling. If aUser() and aCourse() builders go into the shared library, they get tied to the domain model of several services. A change in one service requires a library release, and that requires updating all the services.
  • Dependency hell. The library pulls in Spring Boot, Testcontainers and Mockito versions. A service wants to upgrade Boot, but the library is tied to the old version.
  • A "magic" base class. An AbstractIntegrationTest that hides everything: a new developer doesn't understand how the test is set up, and debugging gets harder.

The limits I set:

  • only infrastructure- and protocol-level helpers: container configurations, auth, HTTP/Kafka test clients, Awaitility templates, ArchUnit rules;
  • domain builders stay inside each service;
  • dependencies as compileOnly/provided or through a BOM, so the library doesn't force versions;
  • semver and a changelog; every release is tried on at least 2-3 "pilot" services;
  • composition, not inheritance: JUnit extensions and annotations (@WithPostgres), not a mega base class.

To evaluate it, a pilot: wire it into 3 services, and after a month compare the amount of test code, CI time and the teams' opinions. If the library is optional and everyone moves to it anyway, that's the best proof.