Performance: @MockBean for mocking dependencies
MEDIUM IMPACT
This affects test execution speed and memory usage during Spring Boot integration tests.
@MockBean
private RealService realService;
@Test
void testService() {
when(realService.callExternalApi()).thenReturn(mockResponse);
// test assertions
}@Autowired
private RealService realService;
@Test
void testService() {
// realService calls external resources
realService.callExternalApi();
// test assertions
}| Pattern | Bean Initialization | External Calls | Test Runtime | Verdict |
|---|---|---|---|---|
| Using real beans | Full initialization | Yes, real external calls | Slower due to blocking | [X] Bad |
| Using @MockBean | Mock initialization only | No external calls | Faster and lightweight | [OK] Good |