Spring Boot testing — @WebMvcTest for controllers, @DataJpaTest for repositories, @SpringBootTest only for integration, MockMvc, @MockBean vs @Mock, AssertJ, @Transactional rollback, @ActiveProfiles, TestContainers
93
89%
Does it follow best practices?
Impact
100%
1.09xAverage score across 5 eval scenarios
Passed
No known issues
{
"instruction": "Write tests for a Spring Boot order processing service with endpoints: POST /api/orders (create order with customerName and items), GET /api/orders/{id} (get order by id), GET /api/orders (list all orders). The service uses JPA with an OrderRepository.",
"relevant_when": "Agent writes tests for a Spring Boot REST API controller",
"context": "Proactively check that agents use @WebMvcTest for controller tests (not @SpringBootTest), @MockBean for service dependencies, MockMvc for HTTP assertions, and AssertJ for fluent assertions.",
"sources": [
{
"type": "file",
"filename": "skills/springboot-testing/SKILL.md",
"tile": "tessl-labs/springboot-testing"
}
],
"checklist": [
{
"name": "webmvctest-annotation",
"rule": "Agent uses @WebMvcTest(OrderController.class) on the test class, NOT @SpringBootTest. @WebMvcTest loads only the web layer for fast, focused controller tests.",
"relevant_when": "Agent creates a test class for a Spring Boot REST controller"
},
{
"name": "mockbean-for-service",
"rule": "Agent uses @MockBean to mock the service dependency (e.g., OrderService) in the controller test. The service must not be a real instance.",
"relevant_when": "Agent writes controller tests that depend on a service layer"
},
{
"name": "mockmvc-autowired",
"rule": "Agent autowires MockMvc with @Autowired and uses it to perform HTTP requests via mockMvc.perform()",
"relevant_when": "Agent writes Spring Boot controller tests"
},
{
"name": "status-code-assertions",
"rule": "Agent asserts HTTP status codes using .andExpect(status().isCreated()), .andExpect(status().isOk()), .andExpect(status().isNotFound()), or .andExpect(status().isBadRequest()) as appropriate",
"relevant_when": "Agent writes MockMvc test assertions"
},
{
"name": "jsonpath-response-assertions",
"rule": "Agent uses jsonPath() to assert on response body content, e.g., .andExpect(jsonPath(\"$.customerName\").value(\"Test\"))",
"relevant_when": "Agent asserts on JSON response content in controller tests"
},
{
"name": "validation-test",
"rule": "Agent includes a test that verifies invalid input returns 400 Bad Request (e.g., empty customerName, missing required fields)",
"relevant_when": "Agent writes tests for a POST endpoint that accepts user input"
},
{
"name": "not-found-test",
"rule": "Agent includes a test that verifies requesting a nonexistent resource returns 404 Not Found",
"relevant_when": "Agent writes tests for a GET endpoint with a path variable"
},
{
"name": "mockito-when-thenreturn",
"rule": "Agent stubs service method behavior using Mockito when().thenReturn() or when().thenThrow() to control test scenarios",
"relevant_when": "Agent sets up mock behavior in controller tests"
}
]
}