spring-boot-test-patterns

Implement Spring Boot test patterns for unit, slice, and integration tests.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/rizaldiem/digital-invitation-web_V2 --skill spring-boot-test-patterns-rizaldiem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-boot-test-patterns
Source: https://github.com/rizaldiem/digital-invitation-web_V2/tree/main/.windsurf/skills/spring-boot-test-patterns
Command: npx skills add https://github.com/rizaldiem/digital-invitation-web_V2 --skill spring-boot-test-patterns-rizaldiem

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides comprehensive guidance for building robust Spring Boot test suites across unit, slice, and integration tests, including patterns, annotations, and container-based strategies.

Core Features & Use Cases

  • Coverage of unit tests with Mockito, slice tests with DataJpaTest and WebMvcTest, and full integration tests with SpringBootTest and Testcontainers.
  • Guidance on using @ServiceConnection, dynamic properties, and context caching for fast, deterministic runs.
  • Use cases include repository testing against real databases, REST API controller tests, and service layer validation in CI pipelines.

Quick Start

Apply the Spring Boot testing patterns to bootstrap a robust unit, slice, and integration test strategy in your project.

Frequently Asked Questions about spring-boot-test-patterns

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

FAQPage Schema
How do I structure Spring Boot tests across unit, slice, and integration layers?

Structure Spring Boot tests by applying Mockito for unit tests, @WebMvcTest and @DataJpaTest for slice tests, and @SpringBootTest with Testcontainers for integration tests. This pattern ensures fast, deterministic feedback across repository, service, and controller layers.

What is the best way to test Spring Boot repositories against a real database in CI?

The best way to test Spring Boot repositories against a real database is using @DataJpaTest slice tests combined with Testcontainers. This approach spins up disposable database containers in Docker-enabled CI environments, ensuring deterministic repository validation.

How does @ServiceConnection work with Testcontainers in Spring Boot integration tests?

@ServiceConnection works with Testcontainers by automatically configuring Spring Boot's data source properties from dynamic container ports. This eliminates manual property management, enabling fast context caching and deterministic full-context integration test runs.

Do I need Docker configured to run Spring Boot integration tests with Testcontainers?

Yes, Docker is required to run Spring Boot integration tests with Testcontainers. Your CI environment must be Docker-enabled to spin up the containerized databases and services needed for fast, deterministic @SpringBootTest execution.

Why use slice tests like @WebMvcTest instead of full @SpringBootTest for controllers?

Use @WebMvcTest slice tests instead of @SpringBootTest to load only the web layer without starting the full application context. This isolates REST API controller tests, providing faster feedback and deterministic validation via MockMvc.

Can I use Mockito and WebTestClient together in Spring Boot slice tests?

Yes, you can use Mockito and WebTestClient together in Spring Boot slice tests. Mockito mocks service layer dependencies while WebTestClient validates reactive or non-blocking REST API controller behaviors, ensuring fast and isolated web layer testing.