Instant Mockito [Instant]
|Print & eBook also available on:|
- 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
Book DetailsLanguage : English
eBook : 66 pages
Release Date : August 2013
ISBN : 1782167978
ISBN 13 : 9781782167976
Author(s) : Marcin Grzejszczak
Topics and Technologies : All Books, Application Development, Instant, Open Source
Table of ContentsInstant Mockito
- Instant Mockito
- So, what is Mockito?
- Using Mockito
- Integrating Mockito within your existing websites/applications
- Step 1 – what do I need?
- Step 2 – attaching JARs to the classpath
- And that's it
- Quick start – creating your first unit test with Mockito
- Step 1 – picking a class that you want to unit test
- Step 2 – picking a method that you want to unit test
- Step 3 – creating a unit test class with a properly defined method
- Step 4 – creating mocks and setting them in the object under testing
- Step 5 – defining, executing, and verifying mock behavior
- 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
- Removing boilerplate code by using MockitoJUnitRunner
- Removing boilerplate code when you can't use MockitoJUnitRunner
- Taking advantage of advanced mocks configuration
- Getting more information on NullPointerException
- Providing additional interfaces
- People and places you should get to know
- Official sites
- Articles and tutorials
Download the code and support files for this book.
Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.
Sorry, there are currently no downloads available for this title.
What you will learn from this book
- Create stubs, mocks, and spies
- Perform argument matching
- Work with void methods and thrown exceptions
- Perform stubbing with a custom answer
- Verify the behaviour of mocks
- Perform argument capturing
- Verify the call order
- Work with asynchronous code
- Learn about partial mocking
- Reduce boilerplate code with annotations
- Learn about advanced mock configuration
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.
Filled with practical, step-by-step instructions and clear explanations for the most important and useful tasks. This is a standard, tutorial-based guide using plenty of examples for illustration.
Who this book is for
Instant Mockito is ideal for developers new to unit testing, who are looking to get to know how to create high quality tests using Mockito. It’s assumed that you will have some experience in Java already.