Growing Object-Oriented Software Guided by Tests - Book Review
This is a review of "Growing Object-Oriented Software Guided by Tests" book by Steve Freeman and Nat Pryce (Addison Wesley, 2009)
This book is so great that I could write tons about it, but I tried to keep it reasonably short. :)
Some books give you information about a specific technology. They are useful, but not irreplaceable. With enough determination one can acquire roughly the same knowledge by gathering data scattered among tutorials, javadocs, FAQs, mailing lists and blog entries.
Another category of books share knowledge based on experience rather than information. Such books are invaluable if written by people with real experience. This book is one of this rare kind.
Three Books in One
The book is really "three books in one" (or maybe more). It contains a great introduction to TDD and end-to-end testing, a step by step presentation of application development and a plethora of good practices regarding various problems of testing and development.
TDD and End-to-End testing
Ah, plenty of interesting things here. I learned a lot of new things, even though I already know and read a lot about topics that are discussed in the book. Walking skeletons, end-to-end testing, building on top of 3rd party libraries, types of object peers. Well written, concise, illustrated with real-life stories and good examples, and always with practice on mind.
The application they present is an auction sniper (a tool that keeps track of various auctions and bids automatically if needed). Some features of sniper are missing, but still you can treat the application as complete, in a sense that it has a frontend (Swing GUI), some business logic, and talks using XMPP protocol to another (chat) application.
This part of the book is harder to follow. You need to read very carefully to understand the design issues they describe. I got lost more than few times, and I had to go back in order to catch the idea.
Even if it is sometimes not an easy lecture, it is very fruitful. You can see how a real application problems can be solved using rigorous (but pragmatic) TDD approach.
The sweet thing here is that you can see not only what choices the authors (experienced programmers) make but you can also read why they took such and such decision.
It is like sitting next to a great coder, looking at what he does, and listening to his explanation on why he does it. Invaluable.
This part of the book discusses various issues related to testing. It starts with presentation of bad smells in test code, then explains what does it mean to "list to the tests" and how to create complex test objects. Then it moves to clear expectations, maintainability and flexibility of tests. Finally it moves to "advanced topics" - testing of persistence, threads and asynchronous calls.
The only argument against this part of the book that I can find, is that it should be much longer. :)
It is a real pleasure to read this book. It is full of nice "best practices", tips and tricks, and additional notes on various coding issues.
Sometimes I was glad to see that the authors follow the same patterns that I do. Sometimes I felt challenged when they suggested me to break the old habits (like using
XYZImpl naming patter) and gave good reasons for this. Sometimes I felt puzzled and uneasy when they proposed something what on the first look seemed weird but after the second reading... "well... hmmm... I have never thought about this...".
In any case they made me rethink my coding habits and gave me interesting ideas on how to improve my way of coding. I enjoyed it very much.
You can learn few technologies here too:
- jMock - presented in details in all its power and glory;
- jUnit - introduction only, good enough to follow the code examples (use of jUnit is a disappointment for me, as I value TestNG much more);
- Hamcrest - a whole appendix is devoted to present this matcher library;
- WindowLicker - "a framework for the test-driven development of Java systems through the GUI" that can deal with asynchronous nature of Swing or AJAX calls.
This book is a must-have. It is a pleasure to read, and gives you plenty to think about. Just go and buy it.