Skip to content
Skills Library
Programming · Review & audit

backend-spring-test

/backend-spring-test

Use when reviewing Spring Boot test code — test slice selection (`@SpringBootTest` vs `@WebMvcTest` vs `@DataJpaTest`), `@MockBean` overuse, Testcontainers vs H2, `@DirtiesContext` hygiene, security context in tests. Triggers when Spring Boot test files are in scope.

Repository
tesseract ↗
Licence
MIT
Last repository change
22.06.2026

Assessment and security

95/ 100Class: good
Format20 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 22.06.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when reviewing Spring Boot test code — test slice selection (`@SpringBootTest` vs `@WebMvcTest` vs `@DataJpaTest`), `@MockBean` overuse, Testcontainers vs H2, `@DirtiesContext` hygiene, security context in tests. Triggers when Spring Boot test files are in scope.

Original author description

Use when reviewing Spring Boot test code — test slice selection (`@SpringBootTest` vs `@WebMvcTest` vs `@DataJpaTest`), `@MockBean` overuse, Testcontainers vs H2, `@DirtiesContext` hygiene, security context in tests. Triggers when Spring Boot test files are in scope.

How it works

  1. Overview
  2. Version Compatibility
  3. When to Use
  4. When NOT to Use
  5. Review Process
  6. Evaluation Points
  7. Critical Checks
  8. Severity Guide
  9. Common Mistakes
  10. Related Skills
Original SKILL.md headings · 86 lines, 791 words
SKILL.md preview
---
name: backend-spring-test
description: Use when reviewing Spring Boot test code — test slice selection (`@SpringBootTest` vs `@WebMvcTest` vs `@DataJpaTest`), `@MockBean` overuse, Testcontainers vs H2, `@DirtiesContext` hygiene, security context in tests. Triggers when Spring Boot test files are in scope.
spring_boot_versions: ["3.x"]
---

# Spring Test Review

## Overview

Review Spring Boot tests for appropriate slice scope, mock placement, and context isolation. Pairs with the agnostic `testing-strategy-review` (which covers test pyramid, mocking SUT, flaky patterns).

Triggers when `spring-boot-starter-test` is detected and test source files are in scope. The agnostic skill flags WHAT is wrong with a test; this skill flags HOW Spring's test annotations should be used.

## Version Compatibility

**Supported:** Spring Boot 3.x (declared via `spring_boot_versions: ["3.x"]` in frontmatter).

**Spring Boot 2.x — degraded coverage:**
- All checks (ST1–ST10) apply identically across SB2/SB3
- Package paths differ slightly (`jakarta.servlet.*` in SB3 vs `javax.servlet.*` in SB2 for MockMvc/WebMvcTest internals)

**Spring Boot 3.4+:** `@MockBean` was deprecated in Spring Framework 6.2 in favor of `@MockitoBean` / `@MockitoSpyBean`. ST2/ST3 examples in this skill use `@MockBean`; on SB3.4+ codebases prefer `@MockitoBean`. The semantic checks (mock necessity, slice scope) are unchanged.

To extend coverage for SB2 or SB3.4+, follow Pattern A (broaden the rubric) per `shield/skills/backend/EXTENDING-VERSIONS.md`.

## When to Use

- Reviewing `@SpringBootTest`, `@WebMvcTest`, `@DataJpaTest`, etc.
- Reviewing `@MockBean` and `@SpyBean` usage
- Reviewing Testcontainers vs H2 in-memory choices
- Reviewing test security context (`@WithMockUser`, etc.)

## When NOT to Use

- Pure JUnit assertion patterns — use `testing-strategy-review`
- Non-Spring test frameworks (pytest, jest) — different conventions
- Performance test design — separate skill not in v1

## Review Process

1. Inventory: test classes by their primary slice annotation
2. For each, apply Evaluation Points ST1–ST10
3. Cross-cut: confirm `@SpringBootTest` is reserved for full integration, not unit tests in disguise

## Evaluation Points

| # | Check | What to Look For | Severity |
|---|-------|-------------------|----------|
| ST1 | Test slice selection | Use `@WebMvcTest` for controllers, `@DataJpaTest` for repos, `@JsonTest` for serialization, `@SpringBootTest` only when truly integration-shaped | High |
| ST2 | `@MockBean` necessity | Mock collaborators that aren't part of the slice. Don't mock everything — slice annotations auto-configure the layer | Medium |
| ST3 | `@SpringBootTest` scope | Full context boot is slow. Justify when a smaller slice would work | High |
| ST4 | `@DirtiesContext` minimization | Recreating the context per test is very slow. Use only when absolutely required (rare); prefer test-data isolation via transactions or `@Sql` | High |
| ST5 | Testcontainers vs H2 | Testcontainers gives a real database (catches dialect issues). H2 is faster but masks production differences. Choose deliberately | Medium |
| ST6 | Test security context | `@WithMockUser`, `@WithUserDetails`, or custom security context. Don't disable security in tests | Medium |
| ST7 | `@Transactional` in tests | Tests marked `@Transactional` roll back automatically — good for isolation. Avoid in tests that span multiple transactions | Medium |
| ST8 | MockMvc vs WebTestClient | MockMvc for MVC; WebTestClient for WebFlux. Don't mix layers | Low |
| ST9 | Parallel test safety | If tests run in parallel, no shared mutable state across classes. `@Execution(SAME_THREAD)` for legacy tests | Medium |
| ST10 | Test data setup | `@Sql` for repo tests, `TestEntityManager.persist` in `@DataJpaTest`. Don't rely on schema state from prior tests | Medium |

## Critical Checks

- `@SpringBootTest` on a test that exercises one controller (slice annotation would be faster)
- `@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)` (extremely slow)
- A test class with 5+ `@MockBean`s (smell — the slice is wrong)
- A test that asserts on database state without resetting between methods

## Severity Guide

| Severity | When |
|---|---|
| High | CI slowness or false confidence (heavy slice for unit-shaped test, no assertions, dirties-context per method) |
| Medium | Friction during normal feature work (wrong mock placement, missing isolation) |
| Low | Style — slice consistency, minor naming |

## Common Mistakes

| Mistake | Fix |
|---|---|
| Demanding `@WebMvcTest` for every controller test | Some controllers genuinely need the full context (e.g., to verify security filters interact). The smell is when `@WebMvcTest` would clearly suffice |
| Flagging all `@MockBean` usage | `@MockBean` is the right tool for external dependencies. The smell is mocking domain services already in the slice |
| Insisting on Testcontainers always | H2 is fine for repo tests that don't exercise dialect-specific SQL. Testcontainers is required when SQL features differ |
| Treating `@Transactional` tests as anti-pattern | Tx-rollback tests give clean isolation. The smell is using them when the test must span transactions (e.g., testing a saga) |
| Demanding security context in every test | Pure unit tests don't need it. The smell is integration tests bypassing security to "make tests pass" |

## Related Skills

- For test pyramid balance, mock SUT, flaky patterns → `backend-testing-strategy-review`
- For JPA repository test patterns → `backend-spring-data` (P5–P8)
- For controller test patterns alongside `@WebMvcTest` → `backend-spring-web` (W4)

Versions

The database has no other skills named backend-spring-test.

Database snapshot: 13.11.2026 · package version 0b9b5aa2cff0 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100spring-boot-test
    Spring Boot testing fundamentals including @SpringBootTest, slice tests, MockMvc, mocking with @MockBean, test configuration, and testing utilities. For integration tests with Testcontainers, see spring-boot-integration. USE WHEN: user mentions "spring boot test", "mockmvc",…
  • 100spring-boot-testing
    Spring Boot 4 testing strategies and patterns. Use when writing unit tests, slice tests (@WebMvcTest, @DataJpaTest), integration tests, Testcontainers with @ServiceConnection, security testing (@WithMockUser, JWT), or Modulith event testing with Scenario API. Covers the critical…
  • 100spring-boot-testing
    How to test Spring Boot 4.x applications: unit tests with JUnit 5 and Mockito, slice tests (@WebMvcTest with MockMvcTester, @DataJpaTest), @SpringBootTest integration tests with Testcontainers and @ServiceConnection, test data setup, ArchUnit architecture rules, and which test…
  • 100spring-boot-test-patterns
    Provides comprehensive testing patterns for Spring Boot applications covering unit, integration, slice, and container-based testing with JUnit 5, Mockito, Testcontainers, and performance optimization. Use when writing tests, @Test methods, @MockBean mocks, or implementing test…
  • 100spring-boot-integration
    Spring Boot integration testing with Testcontainers, sliced tests, and full context. Covers real database testing, API integration, and end-to-end flows. USE WHEN: user mentions "spring integration test", "testcontainers spring", "full context test", asks about "@SpringBootTest…
  • 100spring-testing
    Write, repair, and modernise tests in an existing Spring Boot 4 project (Maven or Gradle) — Testcontainers 2.x, integration vs unit routing, and the Boot 4 test API (@MockitoBean, MockMvcTester, RestTestClient). Use when asked to add or fix tests, set up Testcontainers, or…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.