Lesson 2 of 615 minModule progress 0%

Module 17: Professional Development Practices

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.

Advertisement

Lesson check

Which Mockito API confirms a dependency was called?

Next lesson →