Skip to content

Instantly share code, notes, and snippets.

@shaunthomas999
Last active November 4, 2019 14:54
Show Gist options
  • Save shaunthomas999/8b1c251cced1af7dfe11b8cbfdc0444b to your computer and use it in GitHub Desktop.
Save shaunthomas999/8b1c251cced1af7dfe11b8cbfdc0444b to your computer and use it in GitHub Desktop.
Mockito Reference

Usage of Mockito API

// If want to use chain method calls then use 'RETURNS_DEEP_STUBS' property
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
Foo foo = mock(Foo.class, RETURNS_DEEP_STUBS);

@Mock (answer = Answers.RETURNS_DEEP_STUBS)
private Foo foo;
  • Answers.CALLS_REAL_METHODS - Calls real methods instead of stubs
// When a return value of a real objects method has to be mocked, use 'spy'
Voo voo = spy(new Voo());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment