Java Learner logo

Module 17: Professional Development Practices

Lesson focus

Mocking with Mockito

Isolate units by mocking collaborators and verifying interactions.

Extend tests with MockitoExtension to enable annotations like @Mock and @InjectMocks.

Stub behaviors using when(...).thenReturn(...) or thenThrow(...) and verify interactions with verify(...).

Avoid over-mocking; rely on integration tests for cross-component behavior.

Lesson quiz

Which Mockito API confirms a dependency was called?

Next lesson →