A useful Spring test chooses the narrowest execution layer that can observe the failure it claims to verify.
Spring test failures: prove the layer that can reject the request
The examples exercise different boundaries
Standalone MockMvc sees the two validation paths and the advice added to that builder. It does not prove the advice is discovered in the full application. A Spring application context is needed to see @Async and method-security proxy interception. H2 with a transaction manager is needed to see a savepoint rollback. A live HTTP or deployment test is needed to see network, filters and proxy behavior together.
This is not a ranking of tests. The failure's owner determines the test. MVC validation, async completion and nested rollback each have a different observable result. A unit test that calls the target method directly cannot establish that an interceptor applied.
Record what did not run
When a rejected MVC input returns 400, assert that the handler did not mutate state. When a transaction throws, query the final rows. When a secured call is denied, check the target state. Status codes alone are weaker evidence than the side effects they are meant to prevent. Current fixtures cover local boundaries, not a production database or real authentication provider.
Checked source
client.perform(get("/contract/receipt-limit").param("count", "0"))
.andExpect(status().isBadRequest());
assertEquals(List.of("accept", "record-rejection"),
jdbc.queryForList("select step from receipt_step order by step", String.class));Verification boundary
MvcValidationModesTest.objectAndDirectParameterConstraintsRejectDifferentInputs and NestedSavepointContractTest.nestedFailureRollsBackToSavepointWhileOuterWorkCommits runs in the downloadable Spring source kit. The excerpt omits imports and surrounding setup; the kit contains the complete tests.
Costs and limits
Focused tests are quick but omit layers by design. The two excerpts come from separate local fixtures; together they do not prove a complete web-to-database flow or deployment failure recovery.
Common Mistakes
- Do not claim an HTTP filter was checked by a standalone controller test.
- Do not claim transaction rollback from an exception assertion alone; inspect rows.
- Do not call a direct target-method test proof of proxy advice.
Read next
Spring tests: separate business rules, wiring and transport, Spring MockMvc standalone tests: know which HTTP layers were assembled, Spring nested transactions: roll back one step to a JDBC savepoint.
