
Testing
Mockito Spy Usage Without Hurting Your Test Design
Use Mockito spy to stub part of a real object, learn the doReturn syntax, and see why a spy often signals a class that should be split instead.
6 min read
Tag
3 posts

Use Mockito spy to stub part of a real object, learn the doReturn syntax, and see why a spy often signals a class that should be split instead.

Set up Mockito with JUnit 5 using MockitoExtension, Mock, InjectMocks and Captor, choose strictness, and avoid manual MockitoAnnotations.openMocks calls.

A Mockito tutorial: create mocks, stub return values and exceptions, verify calls and arguments, and know where mocks help a test and where they hurt.