github/awesome-copilot / skills/spring-boot-testing
spring-boot-testing
VerifiedExpert 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.3 KB |
| references/assertj-basics.md | markdown | 4.3 KB |
| references/assertj-collections.md | markdown | 4.9 KB |
| references/context-caching.md | markdown | 2.4 KB |
| references/datajpatest.md | markdown | 5.0 KB |
| references/failsafe-integration-tests.md | markdown | 2.5 KB |
| references/instancio.md | markdown | 4.9 KB |
| references/mockitobean.md | markdown | 4.5 KB |
| references/mockmvc-classic.md | markdown | 5.8 KB |
| references/mockmvc-tester.md | markdown | 7.5 KB |
| references/restclienttest.md | markdown | 4.6 KB |
| references/resttestclient.md | markdown | 4.9 KB |
| references/sb4-migration.md | markdown | 3.3 KB |
| references/test-slices-overview.md | markdown | 5.5 KB |
| references/testcontainers-jdbc.md | markdown | 7.7 KB |
| references/webmvctest.md | markdown | 3.6 KB |
references/sb4-migration.md
View on GitHub# Spring Boot 4.0 Migration
Key testing changes when migrating from Spring Boot 3.x to 4.0. For the full migration workflow (annotations, packages, `@SpringBootTest` changes, `TestRestTemplate`), use the `spring-boot-4-migration` skill (`references/08-testing.md`).
## Dependency Changes
### Modular Test Starters
Spring Boot 4.0 introduces modular test starters:
**Before (3.x):**
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
```
**After (4.0) - WebMvc Testing:**
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
```
**After (4.0) - REST Client Testing:**
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-restclient-test</artifactId>
<scope>test</scope>
</dependency>
```
## Annotation Migration
`@MockBean`/`@SpyBean` are replaced by `@MockitoBean`/`@MockitoSpyBean`; see `spring-boot-4-migration` (`references/08-testing.md`) for the package changes.
## New Testing Features
### RestTestClient
Replaces TestRestTemplate (deprecated):
```java
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureRestTestClient
class OrderIntegrationTest {
@Autowired
private RestTestClient restClient;
@Test
void shouldCreateOrder() {
restClient
.post()
.uri("/orders")
.body(new OrderRequest("Product", 2))
.exchange()
.expectStatus()
.isCreated()
.expectHeader()
.location("/orders/1");
}
}
```
## JUnit 6 Support
Spring Boot 4.0 uses JUnit 6 by default:
- JUnit 4 is deprecated (use JUnit Vintage temporarily)
- All JUnit 5 features still work
- Remove JUnit 4 dependencies for clean migration
## Testcontainers 2.0
Module naming changed:
**Before (1.x):**
```xml
<artifactId>postgresql</artifactId>
```
**After (2.0):**
```xml
<artifactId>testcontainers-postgresql</artifactId>
```
## Non-Singleton Bean Mocking
Spring Framework 7 allows mocking prototype-scoped beans:
```java
@Component
@Scope("prototype")
public class OrderProcessor { }
@SpringBootTest
class OrderServiceTest {
@MockitoBean
private OrderProcessor orderProcessor; // Now works!
}
```
## SpringExtension Context Changes
Extension context is now test-method scoped by default.
If tests fail with @Nested classes:
```java
@SpringExtensionConfig(useTestClassScopedExtensionContext = true)
@SpringBootTest
class OrderTest {
// Use old behavior
}
```
## Migration Checklist
- [ ] Replace @MockBean with @MockitoBean
- [ ] Replace @SpyBean with @MockitoSpyBean
- [ ] Update Testcontainers dependencies to 2.0 naming
- [ ] Add modular test starters as needed
- [ ] Migrate TestRestTemplate to RestTestClient
- [ ] Remove JUnit 4 dependencies
- [ ] Update custom TestExecutionListener implementations
- [ ] Test @Nested class behavior
## Backward Compatibility
The classic starters (for example `spring-boot-starter-test-classic`) are a temporary aid that restores the Boot 3 module granularity only. They do not restore old packages or `@MockBean`/`@SpyBean`, and you still declare the technology starters. See the `spring-boot-4-migration` skill (`references/02-starters-and-removed-features.md`).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |