Book Image

Test-Driven Development with Mockito

By : Sujoy Acharya
Book Image

Test-Driven Development with Mockito

By: Sujoy Acharya

Overview of this book

<p>The usual life cycle of code involves adding code, breaking an existing functionality, fixing that and breaking a new area! This fragility can be fixed using automated tests and Test Driven Development.<br /><br />TDD’s test first approach expedites the development process and unit tests act as safety nets for code refactoring and help in maintaining and extending the code. This makes TDD highly beneficial for new projects.<br /><br />This practical, hands-on guide provides you with a number of clear, step-by-step exercises that will help you to take advantage of the real power that is behind Test Driven Development and the Mockito framework. By using this book, you will gain the knowledge that you need to use the Mockito framework in your project.<br /><br />This book explains the concept of Test Driven Development (TDD), including mocking and refactoring, as well as breaking down the mystery and confusion that surrounds the test first approach of TDD. It will take you through a number of clear, practical examples that will help you to take advantage of TDD with the Mockito framework, quickly and painlessly.<br /><br />You will learn how to write unit tests, refactor code and remove code smells. We will also take a look at mock objects and learn to use Mockito framework to stub, mock, verify and spy objects for testability. You will also learn to write clean, maintainable, and extensible code using design principles and patterns.<br /><br />If you want to take advantage of using Test Driven Development and learn about mocking frameworks, then this is the book for you. You will learn everything you need to know to apply Test Driven Development in a real life project, as well as how to refactor legacy code and write quality code using design patterns.</p>
Table of Contents (18 chapters)
Test-Driven Development with Mockito
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
2
Refactoring – Roll the Dice
7
Leveraging the Mockito Framework in TDD
Index

Exploring continuous integration


Continuous integration is an eXtreme Programming (XP) concept. It was introduced to prevent integration issues. Developers commit code periodically and every commit is built. Automated tests verify whether everything is integrated or not. It helps in the incremental development and periodic delivery of the working software.

Continuous integration is meant to make sure that we're not breaking something unconsciously in our hurry. We want to run the tests continuously and we need to be warned if they fail.

In a good software development team, we'd find TDD as well as CI.

For continuous integration, you need a common code repository to store files (such as SVN, Rational ClearCase, CVS, Git, and so on.), automated builds, and tests.

Every developer works with a local copy of the common code repository and when he is done, he commits his changes to the common repository. Then the automated build process builds the change on the common repository, automated unit tests run and flag error if anything is broken.

If a code compilation or test fails, the developer who made the change gets the information and fixes the code. So, the turnaround time is very quick.

Numerous CI tools are available in the market, CruiseControl and Jenkins are the widely used ones.