spring-testing

Standardize Spring Boot slice and integration tests with Testcontainers and WireMock.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/dprice-dev/claude-java-skills --skill spring-testing-dprice-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-testing
Source: https://github.com/dprice-dev/claude-java-skills/tree/main/.claude/skills/spring-testing
Command: npx skills add https://github.com/dprice-dev/claude-java-skills --skill spring-testing-dprice-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents brittle, flaky Spring Boot test suites by standardizing how to structure slice tests, wire Testcontainers, and choose the right test client for each layer.

Core Features & Use Cases

  • Spring slice test patterns: Uses JUnit 5 + Mockito + AssertJ with correct slice annotations like WebMvcTest, DataJpaTest, and SB4 full-stack MOCK testing.
  • Testcontainers wiring that works in SB4: Provides container setup guidance and the safest wiring approach (including tc: JDBC URLs) to avoid context issues and migration ordering problems.
  • External collaborator stubbing: Demonstrates WireMock for isolating external APIs during integration-style tests.
  • Use case: When a controller test starts failing due to inconsistent setup or wrong client choice, apply the Skill’s slice-specific pattern (MockMvc vs RestTestClient) and the testcontainer strategy for the needed persistence layer.

Quick Start

Set up your next Spring Boot test layer by asking for the correct pattern for your target slice (web, JPA, or full-stack) and how to wire Testcontainers reliably for PostgreSQL.

Frequently Asked Questions about spring-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stop flaky Spring Boot slice tests in enterprise apps?

Stop flaky Spring Boot slice tests by standardizing test patterns with correct slice annotations like WebMvcTest and DataJpaTest alongside Mockito and AssertJ. This ensures consistent context loading and reliable assertions across web, JPA, and full-stack MOCK layers.

What's the best way to wire PostgreSQL Testcontainers in Spring Boot 4 tests?

Wire PostgreSQL Testcontainers reliably in Spring Boot 4 by using tc: JDBC URLs or DynamicPropertySource. This approach avoids context caching issues and migration ordering problems, while navigating ServiceConnection limitations to ensure stable persistence layer integration tests.

When should I use MockMvc vs RestTestClient for Spring Boot integration tests?

Use MockMvc for WebMvcTest controller slices to verify web layer behavior in isolation. Switch to RestTestClient for Spring Boot 4 full-stack MOCK tests and end-to-end RANDOM_PORT tests where you need to validate the entire application context and external API stubs.

How do I stub external APIs with WireMock during Spring Boot integration testing?

Stub external APIs with WireMock during Spring Boot integration testing to isolate collaborator dependencies. This enables reliable end-to-end RANDOM_PORT tests by simulating external service responses without requiring actual network calls to third-party services.

Does DataJpaTest support Testcontainers with PostgreSQL for JPA slice tests?

DataJpaTest supports Testcontainers with PostgreSQL for JPA slice tests by applying reliable container wiring strategies. Using tc: JDBC URLs or DynamicPropertySource ensures the persistence layer loads correctly within the DataJpaTest slice context without triggering full application startup.

Why do my Spring Boot controller tests fail due to inconsistent test setup?

Spring Boot controller tests fail from inconsistent setup when using wrong test clients or missing slice-accurate annotations. Applying the correct WebMvcTest pattern with MockMvc and Mockito standardizes the web slice context, preventing configuration drift and unexpected bean loading failures.