RETURNS_DEEP_STUBS is a Mockito answer strategy that automatically generates mocks for every object returned along a method chain, so you can stub deeply nested calls without manually mocking each intermediate step.
For a.getB().getC().getName(), instead of mocking B and C individually, RETURNS_DEEP_STUBS lets you write when(a.getB().getC().getName()).thenReturn("test") directly.
A a = mock(A.class, RETURNS_DEEP_STUBS);
when(a.getB().getC().getName()).thenReturn("test");
assertEquals("test", a.getB().getC().getName());A concise interview answer is
RETURNS_DEEP_STUBS automatically creates intermediate mocks for every hop in a chained method call, so I can stub something like a.getB().getC().getName() in a single line instead of mocking each object manually. I use it sparingly, since long chains usually point to a design that could be simplified.
Last updated: 16 July 2026
Previous question: How do you mock objects in Mockito when using constructor injection?
Next question: How do you mock behavior for methods that depend on randomness (like Math.random())?