Mockito Essentials
eBook - ePub

Mockito Essentials

  1. 214 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mockito Essentials

About this book

Whether you are new to JUnit testing and mocking or a seasoned Mockito expert, this book will provide you with the skills you need to successfully build and maintain meaningful JUnit test cases and effectively mock external dependencies. At the beginning, this book deals with dummy and fake objects and then moves on to exploring stubs followed by an example on spying. Then, it will show you how to make legacy code testable, mock external dependencies using Mockito, and write testable code for greenfield projects. You will also gain an insight on the concepts of Service-oriented Architecture (SOA) as well as understand how to unit test RESTful web services with Mockito. By sequentially working through the steps in each chapter, you will quickly learn the features of Mockito.

Mockito Essentials will ensure your success with these concepts, tools, and frameworks.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2014
Edition
1
eBook ISBN
9781783983605

Mockito Essentials


Table of Contents

Mockito Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Exploring Test Doubles
Working with unit tests
Understanding test doubles
Using dummy objects
Working with stubs
Exploring a test spy
Getting started with mock objects
Implementing fake objects – simulators
Summary
2. Socializing with Mockito
Exploring Mockito
Exploring unit test qualities
Realizing the significance of Mockito
Working with Mockito
Adding a Mockito dependency
Stubbing method calls
Throwing exceptions
Using argument matchers
Working with wildcard matchers
Working with a custom ArgumentMatcher class
Comparison matchers – equalTo, is, and not
Compound value matchers – either, both, anyOf, allOf, and not
Verifying method calls
Verifying zero and no-more interactions
Answering method calls
Understanding the Mockito architecture
Summary
3. Accelerating Mockito
Learning advanced Mockito features
Working with void methods
Throwing exceptions from void methods
Working with void method callbacks
Learning doCallRealMethod and doNothing
Exploring doReturn
Verifying arguments using ArgumentCaptor
Working with generic collection arguments
Working with variable arguments and arrays
Verifying an invocation order
Spying objects
Exploring Mockito annotations
Changing the default Mockito settings
Resetting mock objects
Working with inline stubbing
Determining mock details
Summary
4. Behavior-driven Development with Mockito
Understanding the context of BDD
Exploring the top-down strategy
Exploring the bottom-up strategy
Finding the gaps
Exploring BDD
Exercising BDD with Mockito
The BDD syntax
Summary
5. Unit Testing the Legacy Code with Mockito
Understanding the legacy code
Exploring testing impediments
Working with PowerMock
Stubbing static methods
Suppressing static blocks
Suppressing a superclass constructor
Suppressing our own constructor
Suppressing methods
Stubbing private methods
Stubbing final methods
Mocking final classes
Designing for testability with Mockito
Identifying constructor issues
Realizing initialization issues
Working with private methods
Working with final methods
Exploring static method issues
Working with final classes
Learning new concerns
Exploring static variables and blocks
Summary
6. Developing SOA with Mockito
Exploring Service-oriented Architecture (SOA)
Working with web services
Exploring JAX-WS with Eclipse
Developing a RESTful web service
Building a RESTful web service with Spring Framework
Summary
7. Unit Testing GWT Code with Mockito
Exploring Ajax and GWT
Learning the MVP pattern
Developing a GWT application using MVP
Unit testing the GWT code
Summary
Index

Mockito Essentials

Copyright © 2014 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2014
Production reference: 1171014
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-360-5
www.packtpub.com
Cover image by Asher Wishkerman ()

Credits

Author
Sujoy Acharya
Reviewers
Christian Baranowski
Tim Perry
Gualtiero Testa
Commissioning Editor
Amarabha Banerjee
Acquisition Editor
James Jones
Content Development Editor
Pooja Nair
Technical Editor
Humera Shaikh
Copy Editors
Dipti Kapadia
Shambhavi Pai
Project Coordinator
Leena Purkait
Proofreaders
Simran Bhogal
Cathy Cumberlidge
Indexers
Mariammal Chettiyar
Tejal Soni
Graphics
Shee...

Table of contents

  1. Mockito Essentials

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Mockito Essentials by Sujoy Acharya in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Java. We have over one million books available in our catalogue for you to explore.