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
{
"context": "Tests whether the agent proactively uses the correct test slice annotations for each layer, configures a test profile with H2, and follows Spring Boot testing best practices across controller, repository, and integration tests. The task does not prescribe which annotations to use for each layer.",
"type": "weighted_checklist",
"checklist": [
{
"name": "@WebMvcTest for controller test",
"description": "BookControllerTest uses @WebMvcTest(BookController.class) for the controller slice test, not @SpringBootTest. The agent was NOT told which annotation to use for the controller test.",
"max_score": 12
},
{
"name": "@DataJpaTest for repository test",
"description": "BookRepositoryTest uses @DataJpaTest for the repository slice test, not @SpringBootTest. The agent was NOT told which annotation to use for the repository test.",
"max_score": 12
},
{
"name": "@SpringBootTest for integration test",
"description": "BookstoreIntegrationTest uses @SpringBootTest for the full integration test (correct choice for cross-layer tests).",
"max_score": 8
},
{
"name": "@MockBean in controller test",
"description": "The controller test uses @MockBean for BookService dependency, not @Mock or a real instance.",
"max_score": 8
},
{
"name": "application-test.yml with H2",
"description": "Test configuration uses H2 in-memory database (jdbc:h2:mem) with create-drop DDL strategy, not the production PostgreSQL connection.",
"max_score": 10
},
{
"name": "@ActiveProfiles(\"test\") on integration test",
"description": "The integration test (or all test classes) use @ActiveProfiles(\"test\") to load the test configuration. The agent was NOT told to use profiles.",
"max_score": 8
},
{
"name": "@Transactional on integration test",
"description": "The integration test uses @Transactional for auto-rollback, not @DirtiesContext or manual cleanup. The agent was NOT told how to handle test isolation.",
"max_score": 8
},
{
"name": "AssertJ assertions used",
"description": "Tests use AssertJ assertThat() for assertions rather than JUnit assertEquals/assertTrue.",
"max_score": 8
},
{
"name": "No @DirtiesContext anywhere",
"description": "No test class uses @DirtiesContext.",
"max_score": 6
},
{
"name": "No manual deleteAll cleanup",
"description": "Repository tests do not manually call deleteAll() in @BeforeEach/@AfterEach, relying instead on @Transactional auto-rollback.",
"max_score": 6
},
{
"name": "MockMvc in controller test",
"description": "The controller test autowires and uses MockMvc with perform(), andExpect() chains.",
"max_score": 5
},
{
"name": "Multiple meaningful tests per file",
"description": "Each test file has at least 2 test methods that test different scenarios (not just trivial variations).",
"max_score": 4
},
{
"name": "spring-boot-starter-test dependency mentioned or assumed",
"description": "Agent either mentions the spring-boot-starter-test dependency or correctly assumes it is present. Does not add unnecessary dependencies.",
"max_score": 5
}
]
}