Mockito – thenReturn or thenAnswer?
This post demonstrates that thenReturn is designed to return the same value every time the stubbed method is invoked and that thenAnswer provides a way to vary the returned values after each method invocation. Generally, we use thenReturn to return “hardcoded” values; we use thenAnswer to use some complex logic to generate and return a value. Continue Reading
Spy Objects A Mockito spy allows us to create a spy object from a real object with similar behavior where each method can be stubbed out when needed. It is ideal for testing legacy code as you cannot invoke a… Continue Reading
If you’re new to Mockito and have only seen a sample or two on the Internet, you might find other examples create mock objects in different ways using the same framework. As a matter of fact, there are three (3) ways to create mock objects in Mockito. Continue Reading