/spring-boot-java:spring-boot-testingfrom spring-boot-java
Expert Spring Boot testing specialist that selects the best testing techniques for your situation: test slices, Testcontainers with @ServiceConnection, Failsafe integration tests, MockitoBean, JUnit and AssertJ. Written for Spring Boot 4 with notes for Boot 3.
Ships in spring-boot-java. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill provides expert guidance for testing Spring Boot applications with modern patterns and best practices. Examples target Spring Boot 4; see the compatibility note below for Boot 3.
Read the project's Spring Boot version and test dependencies before writing tests, and do not upgrade them implicitly.
| Spring Boot 3.x | Spring Boot 4.x | |
|---|---|---|
| JUnit | 5 (Jupiter) | 6 by default (same org.junit.jupiter.api annotations; JUnit 5 tests keep working) |
| Mock beans | @MockitoBean / @MockitoSpyBean from 3.4 (Spring Framework 6.2); @MockBean / @SpyBean are deprecated | @MockitoBean replaces @MockBean (do not use the old ones) |
| Test starters | spring-boot-starter-test covers everything | modular: add spring-boot-starter-webmvc-test, spring-boot-starter-data-jpa-test, ... |
| Slice imports | org.springframework.boot.test.autoconfigure... | moved, e.g. org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest |
| Testcontainers | 1.x names | 2.x names (testcontainers-postgresql) |
Details: references/sb4-migration.md, references/mockitobean.md.
| Scenario | Annotation | Reference |
|---|---|---|
| Controller + HTTP semantics | @WebMvcTest | references/webmvctest.md |
| Repository + JPA queries | @DataJpaTest | references/datajpatest.md |
| REST client + external APIs | @RestClientTest | references/restclienttest.md |
| JSON (de)serialization | @JsonTest | references/test-slices-overview.md |
| Full application | @SpringBootTest | references/test-slices-overview.md |
@ServiceConnection quickstart, PostgreSQL, MySQL, etc.*IT classes silently skipped unless Failsafe is bound; run ./mvnw verifyMaven gotcha: Failsafe declared only in
<pluginManagement>means*ITtests never run. Declare it in<build><plugins>with theintegration-testandverifygoals and run./mvnw verify.
Testing a controller endpoint?
Yes → @WebMvcTest with MockMvcTester
Testing repository queries?
Yes → @DataJpaTest with Testcontainers (real DB)
Testing business logic in service?
Yes → Plain JUnit + Mockito (no Spring context)
Testing external API client?
Yes → @RestClientTest with MockRestServiceServer
Testing JSON mapping?
Yes → @JsonTest
Need full integration test?
Yes → @SpringBootTest with minimal context config
When a method or class is too complex to test effectively:
Example of refactoring recommendation:
// Before: Complex method hard to test
public Order processOrder(OrderRequest request) {
// Validation, discount calculation, payment, inventory, notification...
// 50+ lines of mixed concerns
}
// After: Refactored into testable units
public Order processOrder(OrderRequest request) {
validateOrder(request);
var order = createOrder(request);
applyDiscount(order);
processPayment(order);
updateInventory(order);
sendNotification(order);
return order;
}
Create helper methods for commonly used objects and mock setup to enhance readability and maintainability.
Use descriptive display names to clarify test intent:
@Test
@DisplayName("Should calculate discount for VIP customer")
void shouldCalculateDiscountForVip() { }
@Test
@DisplayName("Should reject order when customer has insufficient credit")
void shouldRejectOrderForInsufficientCredit() { }
Always structure tests in this order:
Write tests with real production scenarios in mind. This makes tests more relatable and helps understand code behavior in actual production cases.
Aim for 80% code coverage as a practical balance between quality and effort. Higher coverage is beneficial but not the only goal.
Use Jacoco maven plugin for coverage reporting and tracking.
Coverage Rules:
What to Prioritize:
See also: https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html and https://docs.spring.io/spring-boot/reference/features/dev-services.html.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- For WebMvc tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
<!-- For Testcontainers -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
LICENSE (opens in a new tab)SOURCE.md (opens in a new tab)references/assertj-basics.md (opens in a new tab)references/assertj-collections.md (opens in a new tab)references/context-caching.md (opens in a new tab)references/datajpatest.md (opens in a new tab)references/failsafe-integration-tests.md (opens in a new tab)references/instancio.md (opens in a new tab)references/mockitobean.md (opens in a new tab)references/mockmvc-classic.md (opens in a new tab)references/mockmvc-tester.md (opens in a new tab)references/restclienttest.md (opens in a new tab)references/resttestclient.md (opens in a new tab)references/sb4-migration.md (opens in a new tab)references/test-slices-overview.md (opens in a new tab)references/testcontainers-jdbc.md (opens in a new tab)references/webmvctest.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub fcakiroglu16/marketplace --plugin spring-boot-java10 skills in this plugin
/create-spring-boot-java-projectCreate a new Spring Boot Java project (Maven or Gradle) from start.spring.io with sensible defaults for configuration, PostgreSQL, logging, security, testing and Docker. Use when asked to scaffold, bootstrap or generate a Spring Boot application. Detects existing project versions and never upgrades implicitly./java-hibernate-jpaDiagnose and fix Hibernate ORM / Jakarta Persistence problems in plain Java: N+1 queries, lazy loading errors, identifier generation, entity equals/hashCode, cascades, pagination, batching, locking, caching, Lombok on entities, and Hibernate 6/7 differences. Use when reviewing or writing JPA entities, mappings, and queries. Framework-neutral./Other plugins' skills for the same job