giuseppe-trisciuoglio avatar

Spring Boot Test Patterns

Gives you battle-tested patterns for Spring Boot testing across the full stack: unit tests with Mockito, slice tests with @DataJpaTest and @WebMvcTest, and integration tests with Testcontainers. The real value is in the performance targets (unit under 50ms, slice under 100ms) and the opinionated guidance on when to use each approach. Covers the newer @ServiceConnection pattern for Spring Boot 3.5+ which cleans up container wiring considerably. The best practice section is blunt about avoiding @DirtiesContext and being strategic with @SpringBootTest since full context loading kills test suite speed. If you're tired of slow tests or confused about which annotation to reach for, this gives you a clear decision tree.

skills.sh installs
4.4K
GitHub stars
369
last updated
Aug 21, 2026

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill spring-boot-test-patterns --agent claude-code

Installs into .claude/skills of the current project.

Files

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 TypeAnnotationTarget TimeUse Case
Unit Tests@ExtendWith(MockitoExtension.class)< 50msBusiness logic without Spring context
Repository Tests@DataJpaTest< 100msDatabase operations with minimal context
Controller Tests@WebMvcTest / @WebFluxTest< 100msREST API layer testing
Integration Tests@SpringBootTest< 500msFull application context with containers
Testcontainers@ServiceConnection / @TestcontainersVariesReal database/message broker containers

Core Concepts

Sponsors

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, Documentation, Debugging, Java & JVM

More from giuseppe-trisciuoglio/developer-kit

All 102
1dotnet avatarcoverage-analysisdotnet/skillsProject-wide code coverage and CRAP (Change Risk Anti-Patterns) score analysis for .NET projects. Calculates CRAP scores per method and surfaces risk hotspots —4.4Kskills.sh installs
2dotnet avatarcreate-skill-testdotnet/skillsScaffolds eval.yaml evaluation specs for agent skills in the dotnet/skills repository. Use when creating skill tests, writing evaluation stimuli, defining grade4Kskills.sh installs
3cursor avatartddcursor/pluginsUse only when the user explicitly asks for TDD, a failing test, or a regression test, OR when the bug has an obvious cheap local test target. Skip when the test3.9Kskills.sh installs
4grafana avatark6-perf-test-websitegrafana/skillsUse when the user wants to performance-test, load-test, or stress-test a public website end-to-end with k6. Produces a hybrid (protocol + browser) test suite, S3.7Kskills.sh installs
5majidmanzarpour avatarthreejs-qa-releasemajidmanzarpour/threejs-game-skillsVerify and release Three.js browser games. Combines playtest QA, automated bot playtests, mobile/responsive checks, production builds, preview verification, sta3.5Kskills.sh installs
6hashicorp avatarprovider-test-patternshashicorp/agent-skillsTerraform provider acceptance test patterns using terraform-plugin-testing with the Plugin Framework. Covers test structure, TestCase/TestStep fields, ConfigSta3.4Kskills.sh installs