Spring Boot Testing
ASecurityUse a focused `@WebMvcTest` for a controller slice. It loads MVC infrastructure and the controller, while downstream services are mocked: ```java @WebMvcTest(OrderController.class) class OrderControllerTest { @Autowired MockMvc mvc; @MockBean OrderService service; @Test void returnsBadRequestWhenRequestIsInvalid() throws Exception { mvc.perform(post("/api/v1/orders") .contentType(MediaType.APPLICATION_JSON) .content("{}")) .andExpect(status().isBadRequest()); } } ``` Use `@Valid` on controlle...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill spring-boot-testing --agent claude-codeAre you the author of Spring Boot Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-spring-boot-testing-fd744ea7)Use a focused `@WebMvcTest` for a controller slice. It loads MVC infrastructure and the controller, while downstream services are mocked:
```java
@WebMvcTest(OrderController.class)
class OrderControllerTest {
@Autowired MockMvc mvc;
@MockBean OrderService service;
@Test
void returnsBadRequestWhenRequestIsInvalid() throws Exception {
mvc.perform(post("/api/v1/orders")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isBadRequest());
}
}
```
Use `@Valid` on controller inputs and put Jakarta constraints on request DTOs. Use AssertJ for Java assertions and verify the typed response, status, validation errors, and RFC 7807 error shape. Mock only downstream dependencies; do not create a broad base class full of `@MockBean`, because changing mocks can reload the application context for every test. Do not call real external services or databases from a slice test; use WireMock for HTTP behavior and Testcontainers for integration tests. Keep tests isolated and follow Red-Green-Refactor.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.