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 uses plain Mockito (@Mock + @InjectMocks) for service unit tests instead of starting a Spring context. The task says 'unit tests' but does not prescribe the testing approach -- the agent should choose @ExtendWith(MockitoExtension.class) with @Mock on its own, NOT @SpringBootTest or @MockBean.",
"type": "weighted_checklist",
"checklist": [
{
"name": "No Spring context loaded",
"description": "The test class does NOT use @SpringBootTest, @WebMvcTest, or any Spring slice annotation. Service unit tests should not start a Spring context. The agent was NOT told to avoid Spring annotations.",
"max_score": 15
},
{
"name": "@ExtendWith(MockitoExtension.class)",
"description": "The test class uses @ExtendWith(MockitoExtension.class) to enable Mockito annotations.",
"max_score": 10
},
{
"name": "@Mock for dependencies",
"description": "PaymentGateway and PaymentRepository are annotated with @Mock (not @MockBean). @Mock is the correct choice for plain unit tests without Spring.",
"max_score": 12
},
{
"name": "@InjectMocks for service under test",
"description": "PaymentService is annotated with @InjectMocks to auto-inject the @Mock dependencies.",
"max_score": 10
},
{
"name": "AssertJ assertions",
"description": "Uses AssertJ assertThat() for assertions. Uses assertThatThrownBy() or similar for exception testing. Does not use JUnit assertEquals.",
"max_score": 10
},
{
"name": "Mockito verify for interactions",
"description": "Uses Mockito verify() to confirm expected interactions: e.g., verify(paymentRepository).save(any()) to confirm the payment was saved, or verify(paymentGateway).charge() was called with correct arguments.",
"max_score": 10
},
{
"name": "Exception test for declined payment",
"description": "A test stubs the gateway to throw PaymentDeclinedException and asserts the exception propagates from processPayment().",
"max_score": 8
},
{
"name": "Exception test for invalid amount",
"description": "A test verifies that zero or negative amount throws IllegalArgumentException.",
"max_score": 8
},
{
"name": "Happy path test",
"description": "A test verifies the full successful flow: gateway charges, repository saves, correct PaymentResult returned.",
"max_score": 8
},
{
"name": "when/thenReturn for stubbing",
"description": "Uses when().thenReturn() to stub gateway and repository responses for the happy path.",
"max_score": 5
},
{
"name": "No @MockBean used",
"description": "Does not use @MockBean (which requires a Spring context). Uses @Mock instead.",
"max_score": 4
}
]
}