Mockito Basics |
Introduction, What is Mockito, Benefits, Setup with Maven/Gradle, Simple Example |
✅ |
|
|
|
Annotations |
@Mock, @InjectMocks, @Spy, @Captor, @RunWith(MockitoJUnitRunner.class), @ExtendWith(MockitoExtension.class) |
✅ |
✅ |
|
|
Mocking & Stubbing |
Creating mocks, when()?thenReturn(), thenThrow(), doReturn(), doThrow(), void methods, Chained stubbing |
✅ |
✅ |
✅ |
|
Verification |
verify(), times(), never(), atLeast(), atMost(), inOrder(), timeout(), verifyNoMoreInteractions() |
✅ |
✅ |
✅ |
|
Argument Matchers |
any(), eq(), ArgumentCaptor, Custom matchers, Hamcrest matchers |
|
✅ |
✅ |
✅ |
Spies |
@Spy annotation, Difference between mock() and spy(), Partial mocking |
|
✅ |
✅ |
|
Mocking Advanced Cases |
Static methods (Mockito.mockStatic), Final classes, Private methods (with PowerMockito), Constructors |
|
|
✅ |
✅ |
BDD Style |
BDDMockito.given(), willReturn(), willThrow(), then(), BDD vs Classic Mockito |
|
✅ |
✅ |
|
Integration with JUnit |
JUnit 4 Runner, JUnit 5 Extension, Assertions with Mockito, Parameterized tests |
✅ |
✅ |
✅ |
|
Spring Integration |
@MockBean, @SpyBean, SpringBootTest with Mockito, Injecting mocks into Spring context |
|
✅ |
✅ |
✅ |
Exception Testing |
thenThrow(), doThrow(), Custom exceptions, Checked vs Unchecked exception mocking |
✅ |
✅ |
✅ |
|
InOrder Verification |
Multiple mocks order verification, Complex interaction order checks, inOrder with argument matchers |
|
✅ |
✅ |
✅ |
Timeout & Async Testing |
verify(mock, timeout()), Async behavior verification, Advanced concurrency scenarios |
|
|
✅ |
✅ |
Best Practices |
Test readability, Avoiding overuse of mocks, Test maintenance, Test isolation principles |
✅ |
✅ |
✅ |
✅ |
Limitations & Pitfalls |
What Mockito cannot do, Common mistakes, Alternatives (EasyMock, JMockit, PowerMockito), Migration strategies |
|
|
✅ |
✅ |