Part 25 · Best practices

Tests that catch wiring, persistence and HTTP failures

Prerequisites: 01-ecosystem

Which test can prove the behavior?

Unit test: rule correctness; Slice test: selected framework boundary; Integration test: real infrastructure; Critical HTTP flow: application behavior. Connections: Unit test to Critical HTTP flow (rule confidence); Slice test to Critical HTTP flow (binding confidence); Integration test to Critical HTTP flow (persistence confidence)
These are complementary test scopes, not a required execution chain. Full-context does not automatically mean real external services. [S48] [S25]

Goal & mental model verified

Boot supports focused test slices and full-context tests. A slice loads a constrained subset; a full application test exercises broader wiring. Different scopes answer different questions.

[S48] [S25]

Worked example · design exercise synthesis

Test pricing rules with ordinary objects; validate controller errors with an MVC slice; exercise repository mappings against a representative database; reserve full application tests for critical integration flows.

[S48] [S25]

Engineering decision synthesis

Pick the cheapest test that can detect the targeted failure. Real infrastructure tests cost time but can expose SQL, serialization and configuration problems that mocks cannot.

[S48] [S25]

Pitfall & diagnosis synthesis

A mocked repository cannot establish real transaction rollback. Test-managed transactions can also conceal commit-time behavior; choose the test boundary to match the production failure.

[S48] [S25]

Improve & validate synthesis

Build a few high-value scenarios: authorization denial, conflict/rollback, malformed requests and startup misconfiguration. Track failure relevance rather than chasing coverage percentage alone.

[S48] [S25]
Keep this: Test the boundary where the defect can actually occur.
Check yourself: Can an MVC slice validate real database rollback?

Not by itself. It typically excludes the persistence infrastructure required to prove it.

Sources & further reading

  1. [S25] HTTP error responses

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: ProblemDetail; Central exception handling

    Read the linked section to validate the mechanism and its version-specific constraints.

  2. [S48] Boot testing

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: Test slices; SpringBootTest; Different test scopes

    Read the linked section to validate the mechanism and its version-specific constraints.