Sunday, March 09, 2014
Book Review: Test Driven Development with Mockito
Recently I was given a reviewer's copy of Test Driven Development with Mockito from the publisher Packt Pub. The fact that I was given a copy of the book in exchange for a written review has in no way influenced my rating of the book.
Test Driven Development with Mockito by Sujoy Acharya is a good introduction to Test Driven Development (TDD) and should get a person new to this methodology up to speed quickly. There are just a couple chapters that actually deal with using Mockito though.
Chapters 1 through 3 bring you up to speed on what TDD is and how to apply it. Chapter 1 gives a definition of TDD and what the methodology is all about. Chapter talks about refactoring: when to do it, when not to do it and when to stop. Chapter 3 talks about applying TDD.
Chapters 4 and 5 start covering the different styles of testing: outside in (mainly used for acceptance and regression testing) and inside out (mainly used in development). Chapter 5 talks about what the author calls test doubles which are stubs, mocks, dummies and fakes.
Chapters 6 and 7 are where we're introduced and shown Mockito in action and how to use it in a TDD environment. You learn how to stub, mock and spy objects which allows you to better test the code's logic and not external dependencies (database connections, email, etc.).
Chapter 8 talks about patterns and gives examples of replacing conditional logic with both the command pattern and the strategy pattern.
Finally chapter 9 talks about adding TDD to legacy code that had no tests originally.
There are two appendixes in the book. Appendix A talks about different tools such as Eclipse and JUnit, while Appendix B talks about agile practices.
Overall I thought the author did a good job of meeting the objectives he set out to meet when writing this book. I wasn't crazy with how some of the code examples were inline text and others were screen shots and there were a couple issues with the text. This book would be good for someone new to TDD and Mockito, but probably not helpful for those who have some experience with either.
For those who like to see actual ratings, I give the book a 4 out of 5 stars.