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
@WebMvcTest for controller test
100%
100%
@DataJpaTest for repository test
100%
100%
@SpringBootTest for integration test
100%
100%
@MockBean in controller test
100%
100%
application-test.yml with H2
100%
100%
@ActiveProfiles("test") on integration test
100%
100%
@Transactional on integration test
0%
100%
AssertJ assertions used
87%
100%
No @DirtiesContext anywhere
100%
100%
No manual deleteAll cleanup
0%
100%
MockMvc in controller test
100%
100%
Multiple meaningful tests per file
100%
100%
spring-boot-starter-test dependency mentioned or assumed
80%
100%
Uses @WebMvcTest not @SpringBootTest
100%
100%
@MockBean for OrderService
100%
100%
MockMvc autowired and used
100%
100%
Mockito when/thenReturn for stubbing
100%
100%
Status code assertions
100%
100%
jsonPath response body assertions
100%
100%
Validation rejection test
100%
100%
Not found test
87%
100%
Content type set on POST
100%
100%
No @DirtiesContext used
100%
100%
AssertJ or proper assertion style
100%
100%
No unnecessary @SpringBootTest or full context
100%
100%
No Spring context loaded
100%
100%
@ExtendWith(MockitoExtension.class)
100%
100%
@Mock for dependencies
100%
100%
@InjectMocks for service under test
100%
100%
AssertJ assertions
100%
100%
Mockito verify for interactions
100%
100%
Exception test for declined payment
100%
100%
Exception test for invalid amount
100%
100%
Happy path test
100%
100%
when/thenReturn for stubbing
100%
100%
No @MockBean used
100%
100%
Uses @DataJpaTest not @SpringBootTest
100%
100%
Repository autowired
100%
100%
TestEntityManager or repository for data setup
100%
100%
AssertJ assertions
100%
100%
No manual cleanup in BeforeEach/AfterEach
0%
100%
Empty result test included
100%
100%
Custom query methods tested
100%
100%
Meaningful test data
100%
100%
No @DirtiesContext
100%
100%
No full context loaded
100%
100%
Save and retrieve round-trip
100%
100%
Uses @SpringBootTest
100%
100%
Uses @AutoConfigureMockMvc or WebTestClient
100%
100%
@Transactional for auto-rollback
0%
100%
@ActiveProfiles("test")
100%
100%
Test application-test.yml with H2
100%
100%
Multi-step flow test (create then retrieve)
100%
100%
Duplicate detection test
100%
100%
Validation error test
100%
100%
No @DirtiesContext
100%
100%
jsonPath or response body assertions
100%
100%
H2 driver and ddl-auto in test config
100%
100%