TRT
Sign in
ApplicationInternalsexecution

Trace: Choose Tests by the Failure They Can Catch

Tests provide evidence about behavior at different boundaries. Unit tests isolate a small decision; integration tests exercise collaboration between components; end-to-end tests validate a user-visible path. Each level trades feedback speed, realism, and setup cost differently.

The Runtime Theory Team8 min read05 steps

trace spine

  1. 01 Name the contract at risk
  2. 02 Choose the right test boundary
  3. 03 Set up controlled collaborators
  4. 04 Assert success and failure cases
  5. 05 Use feedback to refine tests

This trace follows the actual state transitions behind the companion Choose Tests by the Failure They Can Catch. Each step below names its concrete inputs; values illustrate the mechanism and vary across implementations.

Step 1: Name the contract at risk

Tests provide evidence about behavior at different boundaries. Unit tests isolate a small decision; integration tests exercise collaboration between components; end-to-end tests validate a user-visible path. Each level trades feedback speed, realism, and setup cost differently.

Step 2: Choose the right test boundary

A unit test can verify that a retry policy stops after its configured budget. An integration test can verify that the persistence adapter records an idempotency key. An end-to-end test can prove the checkout flow returns the expected result through the deployed browser-facing path.

Step 3: Set up controlled collaborators

Test the invariant at the narrowest level that can expose the failure, then add an integration check when collaboration between components is the risk.

Checkpoint: Test the invariant at the narrowest level that can expose the failure, then add an integration check when collaboration between components is the risk. Confirm this state before advancing to Assert success and failure cases.

Step 4: Assert success and failure cases

High coverage does not prove meaningful behavior was asserted. Tests that duplicate implementation details can block harmless refactoring, while a few end-to-end tests may miss many edge cases. Choose representative contracts and include failure and boundary conditions.

Step 5: Use feedback to refine tests

A service test passes with a mocked database but production loses updates under concurrent requests. Which test layer was missing, and what invariant should the new test exercise?

The trace is done when this check holds: A service test passes with a mocked database but production loses updates under concurrent requests. Compare the outcome against the companion article before making a performance claim.

Hardware, runtime, and observability notes

When tracing Trace: Choose Tests by the Failure They Can Catch in a live production environment (subsystem: execution, primary layer: application), keep the following step-level cost model and diagnostic checklist in mind:

  • Step 1 (application): Name the contract at risk — verifies state invariants before advancing the execution pointer.
  • Step 2 (application): Choose the right test boundary — verifies state invariants before advancing the execution pointer.
  • Step 3 (application): Set up controlled collaborators — verifies state invariants before advancing the execution pointer.
  • Step 4 (application): Assert success and failure cases — verifies state invariants before advancing the execution pointer.
  • Step 5 (application): Use feedback to refine tests — verifies state invariants before advancing the execution pointer.

Every transition across the application boundary carries both a direct CPU/memory cost (cache-line fills, descriptor lookups, lock acquisitions, or context switches) and a tail-latency queueing risk under contention. To verify this trace on your own service, capture latency histograms and hardware/kernel counters across each step boundary, compare cold-cache versus warm-cache execution paths, and confirm that error or timeout branches release all acquired descriptors, locks, and buffers cleanly.

Not started

Sign in to save your learning progress.

Sign in to save