skillfed

spring-boot-test-patterns

Spring Boot Test Patterns guides you through layered testing strategies—from fast unit tests with mocked dependencies to full integration tests with real databases via Testcontainers. Learn focused slice testing with @DataJpaTest and @WebMvcTest, REST API testing with MockMvc, and container setup using @ServiceConnection for Spring Boot 3.5+.

Spring Boot Test Patterns provides comprehensive guidance for writing unit, integration, and slice tests using JUnit 5, Mockito, and Testcontainers.

AI-generated summary based on this skill's SKILL.md

311 37 MIT updated by giuseppe-trisciuoglio

Install

giuseppe-trisciuoglio/developer-kit/spring-boot-test-patterns · repository language: Python

git clone https://github.com/giuseppe-trisciuoglio/developer-kit
cp -r developer-kit/plugins/developer-kit-java/skills/spring-boot-test-patterns ~/.claude/skills/spring-boot-test-patterns
npx skillfed install giuseppe-trisciuoglio/developer-kit/spring-boot-test-patterns

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

What are spring boot testing patterns?

Spring Boot Test Patterns teaches layered testing strategies for Spring Boot applications. It covers unit tests with mocked dependencies, integration tests using Testcontainers for real databases, and focused slice tests via @DataJpaTest and @WebMvcTest. The guide emphasizes test isolation, performance optimization, and REST API testing with MockMvc to help you build comprehensive test suites efficiently.

How do I write spring boot tests with JUnit 5 and Mockito?

Spring Boot Test Patterns shows how to combine JUnit 5 with Mockito for effective testing. Use @Mock for dependencies, @InjectMocks for the class under test, and @ExtendWith(MockitoExtension.class) for annotation support. The guide demonstrates unit test examples, mocking strategies with @MockBean for Spring beans, and integration patterns that layer unit and integration tests for comprehensive coverage.

How do I configure Testcontainers and @ServiceConnection?

Spring Boot Test Patterns covers Testcontainers setup for database testing in Spring Boot 3.5+. Use @ServiceConnection to automatically wire container connections into your application context—no manual URL configuration needed. The guide includes Postgres container examples, shows how @ServiceConnection eliminates boilerplate, and demonstrates integrating Testcontainers with @SpringBootTest for realistic integration tests.

What is @DataJpaTest and @WebMvcTest for slice testing?

Spring Boot Test Patterns explains slice testing patterns using @DataJpaTest for repository testing and @WebMvcTest for controller testing. These annotations load only relevant beans, reducing context rebuild overhead and speeding up test execution. The guide shows repository testing examples, MockMvc usage for REST endpoint validation, and how slice tests isolate layers for faster, focused testing.

How can I optimize spring boot test performance?

Spring Boot Test Patterns addresses test performance optimization by reducing context rebuild overhead through slice testing (@DataJpaTest, @WebMvcTest), reusing application contexts across tests, and leveraging @ServiceConnection to simplify container setup. The guide covers test isolation strategies, CI/CD pipeline integration for automated test execution, and best practices for maintaining fast feedback loops in your test suite.

How do I test Spring Boot REST APIs with MockMvc?

Spring Boot Test Patterns demonstrates REST API testing using MockMvc within @WebMvcTest slices. Learn to mock controller dependencies, perform HTTP requests (GET, POST, PUT, DELETE), validate response status and content, and test error scenarios. The guide includes practical examples of controller testing patterns and shows how @WebMvcTest provides a focused testing environment without loading unnecessary beans.

SKILL.md

rendered from the published skill — quoted content, verbatim

Spring Boot Testing Patterns

Overview

Comprehensive guidance for writing robust test suites for Spring Boot applications using JUnit 5, Mockito, Testcontainers, and performance-optimized slice testing patterns.

When to Use

  • Writing unit tests for services or repositories with mocked dependencies
  • Implementing integration tests with real databases via Testcontainers
  • Testing REST APIs with @WebMvcTest or MockMvc
  • Configuring @ServiceConnection for container management in Spring Boot 3.5+

Quick Reference

Test Type Annotation Target Time Use Case
Unit Tests @ExtendWith(MockitoExtension.class) < 50ms Business logic without Spring context
Repository Tests

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 9 files
plugins/developer-kit-java/skills/spring-boot-test-patterns/SKILL.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/api-reference.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/best-practices.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/ci-cd-configuration.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/slice-testing.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/test-dependencies.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/testcontainers-setup.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/unit-testing.md
plugins/developer-kit-java/skills/spring-boot-test-patterns/references/workflow-patterns.md

Related skills

Tags

junit-framework mock-testing container-orchestration test-automation layer-isolation performance-benchmarking ci-cd-integration database-testing api-validation test-architecture