Arkhe-claude-plugins spring-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 @MockitoBean migration from @MockBean.
install
source · Clone the upstream repo
git clone https://github.com/joaquimscosta/arkhe-claude-plugins
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/joaquimscosta/arkhe-claude-plugins "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/spring-boot/skills/spring-boot-testing" ~/.claude/skills/joaquimscosta-arkhe-claude-plugins-spring-boot-testing && rm -rf "$T"
manifest:
plugins/spring-boot/skills/spring-boot-testing/SKILL.mdsource content
Spring Boot 4 Testing
Comprehensive testing patterns including slice tests, Testcontainers, security testing, and Modulith Scenario API.
Critical Breaking Change
| Old (Boot 3.x) | New (Boot 4.x) | Notes |
|---|---|---|
| | Required migration |
| | Required migration |
(procedural) | (fluent) | New AssertJ-style API |
Implicit | Explicit annotation required | Add to |
MockMvcTester (Spring Boot 4)
New fluent, AssertJ-style API for controller testing:
@WebMvcTest(UserController.class) class UserControllerTest { @Autowired private MockMvcTester mvc; // NEW: Fluent API @Test void getUser_returnsUser() { mvc.get().uri("/users/{id}", 1) .exchange() .assertThat() .hasStatusOk() .bodyJson() .extractingPath("$.name") .isEqualTo("John"); } }
Key Benefits: Fluent assertions, better error messages, AssertJ integration.
Test Annotation Selection
| Test Type | Annotation | Use When |
|---|---|---|
| Controller | | Testing request/response, validation |
| Repository | | Testing queries, entity mapping |
| JSON | | Testing serialization/deserialization |
| REST Client | | Testing external API clients |
| Full Integration | | End-to-end, with real dependencies |
| Module | | Testing bounded context in isolation |
Core Workflow
- Choose test slice → Minimal context for fast tests
- Mock dependencies →
for external services@MockitoBean - Use Testcontainers →
for databases@ServiceConnection - Assert thoroughly → Use AssertJ,
(new),MockMvcTester
(new), WebTestClientRestTestClient - Test security →
, JWT mocking@WithMockUser
Quick Patterns
See EXAMPLES.md for complete working examples including:
- @WebMvcTest with
andMockMvcTester
(Java + Kotlin)@MockitoBean - @DataJpaTest with
for lazy loading verificationTestEntityManager - Testcontainers with
for PostgreSQL/Redis@ServiceConnection - Security Testing with
for role-based access@WithMockUser - Modulith Event Testing with
APIScenario
Detailed References
- Examples: See EXAMPLES.md for complete working code examples
- Troubleshooting: See TROUBLESHOOTING.md for common issues and Boot 4 migration
- Slice Tests: See references/SLICE-TESTS.md for @WebMvcTest, @DataJpaTest, @JsonTest patterns
- Testcontainers: See references/TESTCONTAINERS.md for @ServiceConnection, container reuse
- Security Testing: See references/SECURITY-TESTING.md for @WithMockUser, JWT mocking
- Modulith Testing: See references/MODULITH-TESTING.md for Scenario API, event verification
Anti-Pattern Checklist
| Anti-Pattern | Fix |
|---|---|
Using in Boot 4 | Replace with |
for unit tests | Use appropriate slice annotation |
Missing | Add to verify lazy loading |
| High-cardinality test data | Use minimal, focused fixtures |
| Shared mutable test state | Use or fresh containers |
| No security tests | Add tests for endpoints |
Related Skills
| Need | Skill |
|---|---|
| Security configuration | |
| Module boundaries | |
| Data layer patterns | |
| Controller patterns | |
Critical Reminders
- @MockitoBean is mandatory —
removed in Boot 4@MockBean - Slice tests are fast — Use them for focused testing
- Clear EntityManager — Required to test lazy loading behavior
- @ServiceConnection simplifies Testcontainers — No more
@DynamicPropertySource - Test security explicitly — Don't rely on disabled security