NOW IN BETA

Mockito Made Clear

By Kenneth Kousen

Margaret Eldridge
The Pragmatic Programmers

--

Ken Kousen gives you just what you need to write unit tests with Mockito. Mockito Made Clear: Java Unit Testing with Mocks, Stubs, and Spies is now in beta:

If you’ve only ever run a few JUnit tests or injected stubs into classes to return preset values, it’s time to level up your Java toolbox. Dependencies on other classes and external resources can obscure issues and make bugs hard to detect. You need to test classes in isolation to truly pinpoint your problems. And while you could write dummy classes to replace dependencies yourself, Mockito automates the process and helps you fix your code faster.

Start with the Mockito API to generate fake classes for dependencies, configure how each should respond when their methods are called, and verify that the class under test interacts with dependencies the way you’d expect. Next, build unit tests with the Mockito framework and feel confident not just that methods are called, but that they are called the correct number of times and in the correct order. Along the way, follow clear test examples based on JUnit 5 to create stubs, mocks, and spies and find the source of any problems lurking in Java classes.

Save time, write better code, and have more confidence in your Java programs with Mockito.

https://pragprog.com/newsletter/
https://pragprog.com/newsletter/
Cover of Mockito Made Clear by Ken Kousen featuring a lime and mint as the cover image
Cover of Mockito Made Clear by Ken Kousen

--

--