Testing With Containers Print

  • 0

Disposable environments for tests.

WHAT THEY PROVIDE

A real database, message broker or cache for tests, created and destroyed per run.

WHY THAT BEATS SUBSTITUTES

Tests exercise the actual behaviour, including its quirks.

WHAT IT COSTS

Slower tests than in-memory substitutes.

WHAT TO USE WHERE

Substitutes for unit tests Real dependencies for integration tests

WHAT TO ENSURE

Each test run starts from a known state.

HOW

A fresh container, or a reset between runs.

WHAT TO BE CAREFUL WITH

Tests depending on each other's data Ports conflicting when runs overlap

WHAT TO DO ABOUT PORTS

Let the system assign one, and read it.

WHAT TO WAIT FOR

The dependency being ready, not merely started.

WHY

Tests otherwise fail intermittently, which is worse than failing consistently.

WHAT TO USE

A readiness check, with a timeout.

WHAT TO RUN IN THE PIPELINE

The same setup as locally.

WHY

Divergence produces failures that only appear in one place.

WHAT TO CLEAN UP

Containers and volumes, after every run.

WHY

Build agents otherwise fill their disks.

WHAT TO TEST AGAINST

The built image, not the source tree.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot