Learn how to create stubs, mocks, and spies, and verify their behaviour using Mockito
- Learn something new in an Instant! A short, fast, focused guide delivering immediate results
- Stub methods with callbacks
- Verify the behavior of test mocks
- Assert the arguments passed to functions of mocks
- Create custom argument matchers
Mockito is an open source testing framework for Java that automates unit tests for use in test-driven development (TDD) or behavior-driven development (BDD), decoupling test code from the system under test by eliminating the expect-run-verify pattern. It lets you write beautiful tests with a clean and simple API.
Instant Mockito contains plenty of real-life examples on how to unit test your code. It shows you how to use this testing framework and explains best practices on how to use it effectively.
Instant Mockito helps you break each significant method into a set of practical examples. It will clarify all the concepts of unit testing and Mockito.
You will learn how to properly capture and verify arguments passed into your stubbed methods. We will also take a look at verifying an order and returning custom answers on the stubs. If you want to take advantage of using the Mockito framework’s API to tame your code base, then this is the book for you.
You will learn everything you need to know to unit test your code in a clear, readable, and high quality manner.
Table of contents
- Instant Mockito
- About the Author
- About the Reviewer
1. Instant Mockito
- So, what is Mockito?
- Quick start – creating your first unit test with Mockito
Top 8 features you need to know about
- Performing argument matching
- Stubbing multiple calls
- Working with void methods and thrown exceptions
- Stubbing with a custom answer
- Verifying behavior (including argument capturing, verifying call order, and working with asynchronous code)
- Doing partial mocking (spying)
- Reducing boilerplate code with annotations
- Taking advantage of advanced mocks configuration
- People and places you should get to know
- Title: Instant Mockito
- Release date: August 2013
- Publisher(s): Packt Publishing
- ISBN: 9781782167976
You might also like
Over 65 recipes to get you up and running with unit testing using Mockito In Detail …
Modern Java Recipes
The introduction of functional programming concepts in Java SE 8 was a drastic change for this …
Mastering Software Testing with JUnit 5
A comprehensive, hands-on guide on unit testing framework for Java programming language About This Book In-depth …
Mockito for Spring
Learn all you need to know about the Spring Framework and how to unit test your …