13 September 2025

#Mockito

#Mockito

Key Concepts


S.No Topic Sub-Topics
1 Introduction to Mockito What is Mockito?, Features, Benefits, Use cases, Unit testing overview
2 Mockito Architecture Mocking framework, Core concepts, Stubbing, Verification, Interaction testing
3 Setting up Mockito Maven dependency, Gradle dependency, IDE setup, JUnit integration, Project configuration
4 Annotations in Mockito @Mock, @InjectMocks, @Spy, @Captor, @RunWith(MockitoJUnitRunner.class)
5 Creating Mocks mock() method, @Mock annotation, Spy, Difference between mock and spy, Mocking interfaces
6 Stubbing Methods when-thenReturn, thenThrow, thenAnswer, doReturn, doThrow
7 Verifying Interactions verify(), times(), never(), atLeastOnce(), atMost()
8 Argument Matchers any(), eq(), anyString(), anyInt(), custom matchers
9 Spy vs Mock Partial mocking, Real method call, Difference, Use cases, Limitations
10 Capturing Arguments ArgumentCaptor, capture(), verify, getValue(), getAllValues()
11 BDD Style Testing given(), when(), then(), BDDMockito, Benefits, Examples
12 Mocking Void Methods doNothing(), doThrow(), doAnswer(), verify, Handling exceptions
13 Mocking Static Methods Mockito.mockStatic(), try-with-resources, when-then, Use cases, Best practices
14 Mocking Final Classes & Methods Mockito-inline, Limitations, Stubbing final methods, Use cases, Configuration
15 Mocking Private Methods Partial mocking, Spy, Reflection, PowerMockito, Use cases
16 Consecutive Calls Stubbing thenReturn multiple values, thenThrow multiple exceptions, doAnswer, Chaining calls, Examples
17 Timeouts & Verification verify with timeout, async testing, atLeast(), atMost(), Examples
18 Resetting Mocks reset(), Clear invocations, When to reset, Best practices, Examples
19 Mocking Collections List, Map, Set, Iteration, Stubbing methods
20 Mocking Exceptions thenThrow, doThrow, Handling checked exceptions, Handling runtime exceptions, Use cases
21 Verifying Order of Invocations InOrder, verify sequence, Multiple mocks, Examples, Best practices
22 Timeout Verification verify with timeout, Asynchronous calls, Testing delays, Examples, Best practices
23 Integration with JUnit JUnit 4, JUnit 5, Annotations, Running tests, Reporting
24 Integration with TestNG TestNG setup, Annotations, Assertions, Running tests, Reporting
25 Best Practices in Mockito Reusable mocks, Clear naming, Avoid over-mocking, Use annotations, Maintain readability
26 Mockito & Spring Boot @MockBean, @SpyBean, Application context, Integration tests, Unit tests
27 Behavior-Driven Testing given-when-then, BDDMockito, Readable tests, Real-life scenarios, Best practices
28 Advanced Stubbing Techniques doAnswer, doReturn, doThrow, Chained stubbing, Conditional stubbing
29 Hands-on Projects Mocking service layer, Repository mocking, API testing, Integration with JUnit, Reporting
30 Certification & Career Path Mockito certification, Learning resources, Portfolio projects, Advanced testing skills, Career opportunities

Interview question

Basic

  1. What is Mockito?
  2. What are the main features of Mockito?
  3. Explain the difference between mock and spy.
  4. What is the purpose of mocking in unit testing?
  5. What is a stub in Mockito?
  6. How do you create a mock in Mockito?
  7. How do you create a spy in Mockito?
  8. What is the difference between @Mock and @Spy annotations?
  9. What is @InjectMocks used for?
  10. How do you reset a mock?
  11. What is the difference between mock() and Mockito.mock()?
  12. How do you verify interactions with a mock object?
  13. What is the difference between verify() and when()?
  14. Explain the difference between JUnit and Mockito.
  15. How do you handle void methods in Mockito?
  16. What is doNothing()?
  17. What is doThrow()?
  18. How do you use doAnswer()?
  19. How do you capture method arguments?
  20. What is ArgumentCaptor?
  21. How do you mock an interface?
  22. How do you mock a class?
  23. Can Mockito mock final classes or methods?
  24. Can Mockito mock static methods?
  25. How do you handle checked exceptions in Mockito?

Intermediate

  1. What is BDDMockito?
  2. Explain given-when-then syntax.
  3. How do you perform consecutive stubbing?
  4. How do you stub multiple method calls?
  5. How do you use any() and eq() argument matchers?
  6. What is the difference between any() and anyInt()?
  7. How do you verify method call order?
  8. What is InOrder?
  9. How do you verify method calls happened at least or at most?
  10. How do you verify that a method was never called?
  11. How do you handle asynchronous method calls?
  12. How do you set timeout for verification?
  13. How do you stub a method to throw multiple exceptions?
  14. What is doReturn()?
  15. When would you use doReturn instead of when()?
  16. How do you mock private methods?
  17. How do you mock constructors?
  18. How do you integrate Mockito with JUnit 4?
  19. How do you integrate Mockito with JUnit 5?
  20. How do you integrate Mockito with TestNG?
  21. What are the limitations of Mockito?
  22. How do you mock collections?
  23. How do you mock lists and maps?
  24. How do you mock chained method calls?
  25. How do you mock dynamic return values?

Advanced

  1. How do you use doAnswer for advanced stubbing?
  2. How do you handle argument validation in stubbing?
  3. How do you mock final classes using Mockito-inline?
  4. How do you mock static methods using Mockito 4+?
  5. How do you verify static method invocations?
  6. How do you mock private static methods?
  7. How do you handle deep stubbing?
  8. What is the difference between mockito-core and mockito-inline?
  9. How do you integrate Mockito with Spring Boot?
  10. What is @MockBean?
  11. What is @SpyBean?
  12. How do you write unit tests for service layers?
  13. How do you write unit tests for repository layers?
  14. How do you handle database integration in Mockito?
  15. How do you mock REST APIs in unit tests?
  16. How do you mock SOAP services?
  17. How do you mock WebClient or RestTemplate?
  18. How do you handle exceptions in unit tests using Mockito?
  19. How do you verify that a method throws an exception?
  20. How do you handle optional return types in mocks?
  21. How do you mock void methods that throw exceptions?
  22. How do you perform parameterized tests with Mockito?
  23. How do you use Mockito for data-driven testing?
  24. How do you mock multi-threaded operations?
  25. How do you handle concurrency in unit tests using Mockito?

Expert

  1. How do you implement behavior-driven development (BDD) with Mockito?
  2. How do you create reusable mocks?
  3. How do you structure large-scale unit tests using Mockito?
  4. How do you manage dependencies in complex tests?
  5. How do you mock third-party libraries?
  6. How do you handle API versioning in mocked services?
  7. How do you mock time-dependent methods?
  8. How do you mock random number generation?
  9. How do you handle environment-specific configurations in mocks?
  10. How do you integrate Mockito with CI/CD pipelines?
  11. How do you mock security context in Spring Boot?
  12. How do you mock JWT tokens?
  13. How do you mock OAuth2 authentication?
  14. How do you handle logging in unit tests?
  15. How do you create custom argument matchers?
  16. How do you mock chained builder patterns?
  17. How do you mock complex nested objects?
  18. How do you mock generic types?
  19. How do you handle legacy code testing with Mockito?
  20. How do you mock external systems in unit tests?
  21. How do you enforce best practices in mocking?
  22. How do you maintain test readability in large projects?
  23. How do you measure test coverage for mocked tests?
  24. How do you implement automated test reporting?
  25. How do you prepare for Mockito-based interviews?

Related Topics