November 2024
Intermediate to advanced
300 pages
7h 12m
English
Hand-grown smart stubs are kind of a bad idea. A stub is a simple test construct that returns a hard-coded value. Adding logic in the middle of it is a recipe for wasted time when you get the logic wrong (you eventually will)—which turns it into a smart-ahh…never mind.
You’ll instead represent your stub using Mockito,[12] the de facto standard “mock” library for Java. Using the tool will keep your tests safer and simpler when you need test doubles. It handles the smarts, so you don’t have to.
Here’s the test updated to use Mockito:
| | // ... |
| » | import static org.mockito.ArgumentMatchers.contains; |
| » | import static org.mockito.Mockito.mock; ... |
Read now
Unlock full access