spring-boot-testing

Tests Spring Boot applications using JUnit 5, Mockito, MockMvc, and Testcontainers.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/shengmingzhishu/LeeCommonSkills --skill spring-boot-testing-shengmingzhishu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: spring-boot-testing
Source: https://github.com/shengmingzhishu/LeeCommonSkills/tree/main/.rules-skills/java-stack/.trae/skills/spring-boot-testing
Command: npx skills add https://github.com/shengmingzhishu/LeeCommonSkills --skill spring-boot-testing-shengmingzhishu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Verifying Spring Boot business logic, web endpoints, persistence, and integrations often leads to slow, bloated test suites that over-rely on full-context @SpringBootTest runs. This Skill structures testing by change scope so each layer gets the right test type. ## Core Features & Use Cases - Layered Test Strategy: Matches test depth to change level, from targeted unit tests (L0) up to migration, rollback, and failure-drill evidence (L3). - Framework Guidance: Applies JUnit 5, Mockito, MockMvc/WebTestClient, and Testcontainers to business, web, persistence, and integration scenarios. - Use Case: After modifying a REST controller and its service, run MockMvc tests for parameter validation and error mapping, plus a Testcontainers-backed repository test against a real database to confirm migration behavior. ## Quick Start Ask the AI to write Spring Boot tests for the changed service and controller classes using JUnit 5, Mockito, and MockMvc.

Frequently Asked Questions about spring-boot-testing

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

FAQPage Schema
How do I test a Spring Boot REST controller?▼

Use MockMvc or WebTestClient to test Spring Boot controllers without starting a full server. These tools verify request mapping, parameter validation, response bodies, and error handling in fast, isolated tests.

How to write unit tests for Spring services with Mockito?▼

Annotate the test with @ExtendWith(MockitoExtension.class), declare dependencies with @Mock, and inject them with @InjectMocks. Stub collaborator behavior with when/thenReturn and verify interactions to test business logic in isolation.

What is Testcontainers used for in Spring Boot testing?▼

Testcontainers runs real databases and services in Docker containers during integration tests. It verifies persistence logic, schema migrations, and repository queries against actual infrastructure instead of in-memory substitutes.

When should I avoid @SpringBootTest?▼

Avoid @SpringBootTest for simple business logic checks because loading the full application context is slow. Prefer plain JUnit 5 with Mockito for unit tests and reserve @SpringBootTest for true end-to-end integration scenarios.

MockMvc vs WebTestClient for Spring testing?▼

MockMvc is the standard choice for servlet-based Spring MVC controllers, while WebTestClient fits reactive WebFlux endpoints. Both validate routing, validation, and error mapping without deploying a server.