Test Driven Development: By Example (The Addison-Wesley Signature Series)
|
| List Price: | $44.99 |
| Price: | $37.40 & eligible for FREE Super Saver Shipping on orders over $25. Details |
Availability: Usually ships in 24 hours
Ships from and sold by Amazon.com
33 new or used available from $26.99
Average customer review:Product Details
- Amazon Sales Rank: #70428 in Books
- Published on: 2002-11-18
- Number of items: 1
- Binding: Paperback
- 240 pages
Editorial Reviews
From the Back Cover
Clean code that works--now. This is the seeming contradiction that lies behind much of the pain of programming. Test-driven development replies to this contradiction with a paradox--test the program before you write it.
A new idea? Not at all. Since the dawn of computing, programmers have been specifying the inputs and outputs before programming precisely. Test-driven development takes this age-old idea, mixes it with modern languages and programming environments, and cooks up a tasty stew guaranteed to satisfy your appetite for clean code that works--now.
Developers face complex programming challenges every day, yet they are not always readily prepared to determine the best solution. More often than not, such difficult projects generate a great deal of stress and bad code. To garner the strength and courage needed to surmount seemingly Herculean tasks, programmers should look to test-driven development (TDD), a proven set of techniques that encourage simple designs and test suites that inspire confidence.
By driving development with automated tests and then eliminating duplication, any developer can write reliable, bug-free code no matter what its level of complexity. Moreover, TDD encourages programmers to learn quickly, communicate more clearly, and seek out constructive feedback.
Readers will learn to:
This book follows two TDD projects from start to finish, illustrating techniques programmers can use to easily and dramatically increase the quality of their work. The examples are followed by references to the featured TDD patterns and refactorings. With its emphasis on agile methods and fast development strategies, Test-Driven Development is sure to inspire readers to embrace these under-utilized but powerful techniques.
0321146530B10172002
About the Author
Kent Beck consistently challenges software engineering dogma, promoting ideas like patterns, test-driven development, and Extreme Programming. Currently affiliated with Three Rivers Institute and Agitar Software, he is the author of many Addison-Wesley titles.
Excerpt. © Reprinted by permission. All rights reserved.
Clean code that works, in Ron Jeffries' pithy phrase, is the goal of Test-Driven Development (TDD). Clean code that works is a worthwhile goal for a whole bunch of reasons.
But how do we get to clean code that works? Many forces drive us away from clean code, and even from code that works. Without taking too much counsel of our fears, here's what we do: we drive development with automated tests, a style of development called Test-Driven Development (TDD). In Test-Driven Development, we
These are two simple rules, but they generate complex individual and group behavior with technical implications such as the following.
The two rules imply an order to the tasks of programming.
Red/green/refactor--the TDD mantra.
Assuming for the moment that such a programming style is possible, it further might be possible to dramatically reduce the defect density of code and make the subject of work crystal clear to all involved. If so, then writing only that code which is demanded by failing tests also has social implications.
So the concept is simple, but what's my motivation? Why would a software engineer take on the additional work of writing automated tests? Why would a software engineer work in tiny little steps when his or her mind is capable of great soaring swoops of design? Courage.
Courage
Test-driven development is a way of managing fear during programming. I don't mean fear in a bad way--pow widdle prwogwammew needs a pacifiew-but fear in the legitimate, this-is-a-hard-problem-and-I-can't-see-the-end-from-the-beginning sense. If pain is nature's way of saying "Stop!" then fear is nature's way of saying "Be careful." Being careful is good, but fear has a host of other effects.
None of these effects are helpful when programming, especially when programming something hard. So the question becomes how we face a difficult situation and,
Imagine programming as turning a crank to pull a bucket of water from a well. When the bucket is small, a free-spinning crank is fine. When the bucket is big and full of water, you're going to get tired before the bucket is all the way up. You need a ratchet mechanism to enable you to rest between bouts of cranking. The heavier the bucket, the closer the teeth need to be on the ratchet.
The tests in test-driven development are the teeth of the ratchet. Once we get one test working, we know it is working, now and forever. We are one step closer to having everything working than we were when the test was broken. Now we get the next one working, and the next, and the next. By analogy, the tougher the programming problem, the less ground that each test should cover.
Readers of my book Extreme Programming Explained will notice a difference in tone between Extreme Programming (XP) and TDD. TDD isn't an absolute the way that XP is. XP says, "Here are things you must be able to do to be prepared to evolve further." TDD is a little fuzzier. TDD is an awareness of the gap between decision and feedback during programming, and techniques to control that gap. "What if I do a paper design for a week, then test-drive the code? Is that TDD?" Sure, it's TDD. You were aware of the gap between decision and feedback, and you controlled the gap deliberately.
That said, most people who learn TDD find that their programming practice changed for good. Test Infected is the phrase Erich Gamma coined to describe this shift. You might find yourself writing more tests earlier, and working in smaller steps than you ever dreamed would be sensible. On the other hand, some software engineers learn TDD and then revert to their earlier practices, reserving TDD for special occasions when ordinary programming isn't making progress.
There certainly are programming tasks that can't be driven solely by tests (or at least, not yet). Security software and concurrency, for example, are two topics where TDD is insufficient to mechanically demonstrate that the goals of the software have been met. Although it's true that security relies on essentially defect-free code, it also relies on human judgment about the methods used to secure the software. Subtle concurrency problems can't be reliably duplicated by running the code.
Once you are finished reading this book, you should be ready to
This book is organized in three parts.
I wrote the examples imagining a pair programming session. If you like looking at the map before wandering around, then you may want to go straight to the patterns in Part III and use the examples as illustrations. If you prefer just wandering around and then looking at the map to see where you've been, then try reading through the examples, referring to the patterns when you want more detail about a technique, and using the patterns as a reference. Several reviewers of this book commented they got the most out of the examples when they started up a programming environment, entered the code, and ran the tests as they read.
A note about the examples. Both of the examples, multi-currency calculation and a testing framework, appear simple. There are (and I have seen) complicated, ugly, messy ways of solving the same problems. I could have chosen one of those complicated, ugly, messy solutions, to give the book an air of "reality." However, my goal, and I hope your goal, is to write clean code that works. Before teeing off on the examples as being too simple, spend 15 seconds imagining a programming world in which all code was this clear and direct, where there were no complicated solutions, only apparently complicated problems begging for careful thought. TDD can help you to lead yourself to exactly that careful thought.
0321146530P10172002
Customer Reviews
intriguing ideas, irritatingly presented
The book's scope is well-defined and its methodology (including a running "task list" that is updated at the end of each chapter with strikeouts and new items) is innovative. But it falls sadly short in execution.
The text is overloaded with cutesy digressions that only serve to obscure the topic at hand and irritate the reader. No "Head First" title, this. To read this book is to wish over and over that its author had had the humility to submit it to another editor's series rather than launching it under his own.
Still, there is no other book quite like it on this subject, and I can certainly recommend it for extended bookstore browsing. You may find you are less sensitive than me to Beck's assaults on clarity, in which case by all means go forth and buy.
Good Theory -- But Odd Decisions In Writing
Overall, this was a great read. I love books with tiny chapters, giving you good stopping points where you can meditate on what you just read while you're busy with life's other challenges. Beck goes into TDD as well as design concepts such as you might find in Scott Bain's Emergent Design book. Patterns are also lightly discussed.
I also love Kent Beck's casual writing style. For those of us who don't have 16 hours a day to devote to our computer, it's nice to have some humor and casual speaking happening in a book which only a hardcore reader will read -- like myself.
I give the book 4 stars, but there are a few *glaring* question marks.
First, there is no introductory chapter on using JUnit or any other *Unit.
Kent wouldn't have even had to write such a chapter himself - maybe one of the tech reviewers! You have to give the reader something to go on, even if you just merely assume the reader will use JUnit in a CLI dev environment. Or discuss all the assert calls. I dunno. Weird. But not a huge deal, and I knew how it worked already, anyway.
Second, and this is a biggie, why on Earth Kent would choose as an example writing xUnit for the second section is so beyond me I have no words. He hints later that he likes to write a *Unit library for each new language he learns, as an exercise. But, good lord, it's so hard to wrap your brain around incestuous "writing yourself" concept -- couldn't he just written something else? We're trying to learn TDD here. Geez. I mostly skimmed the whole section as it was too hard to follow.
Third, in that same section, Kent decides he will move away from Java, a language most of us already know and, if not, looks like a whole host of other languages so it's easy to follow and fairly verbose. Right, he decides to use -- ready? -- PYTHON! A language very few people know and has some strange idioms. This would be akin to writing the chapter using arcane Ruby or Perl structures. The whole second section has you trying to catch up on the language and the recursive xUnit example so much that it completely distracts from the TDD lessons.
OK, here's a fourth. Two very good examples for TDD are practically side notes. I used his late-book example of a Triangle class to do TDD for real for the first time and it was an excellent example! I did it all and only when I completed it did I read his tests. It was great, and I look forward to trying out the Fibonacci Sequence which is an *appendix*.
Why not put these in the book and explain them?
But it's still a good read. Try to avoid buying it for $40 - $50 though. I read it in 2 days without much effort, so not sure it's worth the price. But it's still very good despite all this.
Decent Purchase
This book is good, IF you haven't read the Martin Fowlers refactoring the code ( not back to design patterns, but just refactoring ), other than that it has some cool insights ...
Ok to buy and keep it for reference sake ...
Helpful for all XPrs out there
Regards,
Vyas, Anirudh




