June 01, 2022
Mockito Made Clear: Java Unit Testing with Mocks, Stubs, and Spies
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.
Now available in beta from pragprog.com/titles.
Do More with What You Know
From paperbacks and ebooks to online courses and beyond, if you want to create technical content, we may be your perfect partner.
Leverage our 20+ years of experience, our global distribution network, our massive fan base, our relationships with industry leaders, our editorial, production, and marketing prowess, and even our reputation for excellence. Sure, you could go it alone, but with some of the highest royalties in all of traditional publishing and your own personal team, why would you bother?
Shoot us an email at proposals@pragprog.com or visit pragprog.com/publish-with-us for more details today.
Let's publish something together!
Upcoming Author Appearances2022-06-14 Johanna Rothman,
Sooner Safer Happier Meetup
2022-06-30 Johanna Rothman,
Enterprise Agility Champs
Be the First
Sign up for this newsletter at https://pragprog.com/newsletter/ and be the first to hear about our newest content, best promotions, and upcoming events.
Want even more? Follow @pragprog on Twitter and The Pragmatic Programmers on LinkedIn for commentary, news, job openings, and even puzzles.
And while you're here, remember to look up Andy Hunt @PragmaticAndy and Dave Thomas @pragdave, too.
Thanks for your continued support,
By Professional Developers, for Professional Developers PragProg.com
Sent by the Pragmatic Programmers, LLC. • 9650 Strickland Rd Ste 103-255• Raleigh NC 27615
|