Mockito and Test Doubles — Concept Check
Questions on Mockito and Test Doubles. Mockito is the standard Java mocking framework — create mocks, stub behaviour, and verify interactions to isolate units under test.
Questions in this quiz
8 questions on Mockito and Test Doubles — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a test using Mockito, you notice that a method call is not returning the expected stubbed value. What is a likely cause?
- AMockito does not support stubbing methods that return void.
- BThe method is a final method, which Mockito cannot mock by default.
- CThe method was not stubbed correctly using when().thenReturn().
- DMockito automatically resets stubs after each test method.
2.A developer uses @Spy on a real object but finds that a method call is not behaving as expected. What might be the issue?
- ASpies cannot be used with real objects, only mocks.
- BMockito spies require the method to be public.
- CThe method was not stubbed, so the real method is called.
- DThe method is a final method, which cannot be stubbed by Mockito.
3.A test fails because a mock method returns null instead of a stubbed value. What could be a reason?
- AThe method is static, which Mockito cannot mock by default.
- BMockito only supports stubbing methods that return primitive types.
- CThe method was called with different arguments than those used in stubbing.
- DMockito does not support stubbing methods with complex return types.
4.What happens if you call verify() on a mock method that was never called during the test?
- AMockito will log a warning but continue executing the test.
- BMockito will throw an AssertionError, indicating the method was not called.
- CMockito will automatically stub the method for future calls.
- DMockito will silently pass the verification without any errors.
5.A developer uses ArgumentCaptor to capture an argument but finds it null. What might be the issue?
- AMockito does not support capturing arguments from void methods.
- BArgumentCaptor only works with primitive types, not objects.
- CThe method was not called, so ArgumentCaptor has nothing to capture.
- DThe captured argument was not properly initialized in the method.
6.In a test, a method call is stubbed with when().thenReturn(), but the test throws an UnnecessaryStubbingException. Why?
- AMockito requires all stubs to be verified with verify().
- BMockito does not support stubbing methods with void return types.
- CThe method was stubbed with incorrect argument matchers.
- DThe stubbed method was never actually called during the test.
7.A developer uses doThrow() to stub a void method, but the exception is not thrown. What might be wrong?
- AdoThrow() only works with methods that return values, not void methods.
- BThe method is static, which cannot be stubbed by Mockito.
- CThe method was not called with the expected arguments.
- DMockito requires a specific exception type for doThrow().
8.What is the default return value for an unstubbed boolean method in a Mockito mock?
- Atrue
- Bfalse
- Cnull
- D0