Praise for Growing Object-Oriented Software, Guided by Tests
The authors of this book have led a revolution in the craft of programming by controlling the environment in which software grows. Their Petri dish is the mock object, and their microscope is the unit test. This book can show you how these tools introduce a repeatability to your work that would be the envy of any scientist.
Ward Cunningham
At last a book, suffused with code, that exposes the deep symbiosis between TDD and OOD. The authors, pioneers in test-driven development, have packed it with principles, practices, heuristics, and (best of all) anecdotes drawn from their decades of professional experience. Every software craftsman will want to pore over the chapters of worked examples and study the advanced testing and design principles. This ones a keeper.
Robert C. Martin
Design is often discussed in depth, but without empiricism. Testing is often promoted, but within the narrow definition of quality that relates only to the presence or absence of defects. Both of these perspectives are valuable, but each on its own offers little more than the sound of one hand clapping. Steve and Nat bring the two hands together in what deservesand can best be described asapplause. With clarity, reason, and humour, their tour de force reveals a view of design, testing, code, objects, practice, and process that is compelling, practical, and overflowing with insight.
Kevlin Henney, co-author of Pattern-Oriented Software Architecture and 97 Things Every Programmer Should Know
Steve and Nat have written a wonderful book that shares their software craftsmanship with the rest of the world. This is a book that should be studied rather than read, and those who invest sufficient time and energy into this effort will be rewarded with superior development skills.
David Vydra, publisher, testdriven.com
This book presents a unique vision of test-driven development. It describes the mature form of an alternative strain of TDD that sprang up in London in the early 2000s, characterized by a totally end-to-end approach and a deep emphasis on the messaging aspect of objects. If you want to be an expert in the state of the art in TDD, you need to understand the ideas in this book.
Michael Feathers
With this book youll learn the rhythms, nuances in thinking, and effective programming practices for growing tested, well-designed object-oriented applications from the masters.
Rebecca Wirfs-Brock
Growing Object-Oriented Software, Guided by Tests
Steve Freeman and Nat Pryce
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Cape Town Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales
(800) 3823419
For sales outside the United States please contact:
International Sales
Visit us on the Web: informit.com/aw
Library of Congress Cataloging-in-Publication Data:
Freeman, Steve, 1958
Growing object-oriented software, guided by tests / Steve Freeman and Nat Pryce.
p. cm.
ISBN 978-0-321-50362-6 (pbk. : alk. paper) 1. Object-oriented programming
(Computer science) 2. Computer software--Testing. I. Pryce, Nat. II. Title.
QA76.64.F747 2010
005.117--dc22
2009035239
Copyright 2010 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc
Rights and Contracts Department
501 Boylston Street, Suite 900
Boston, MA 02116
Fax (617) 671 3447
ISBN-13: 978032150362-6
ISBN-10: 0321503627
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.
Sixth printing June 2012
To Paola, for all her support; to Philip, who sometimes missed out
Steve
To Lamaan who put up with me spending time writing this book, and Oliver Tarek who did not
Nat
Contents
Foreword
Kent Beck
One of the dilemmas posed by the move to shorter and shorter release cycles is how to release more software in less timeand continue releasing indefinitely. A new perspective is necessary to resolve this dilemma. More than a shift in techniques is needed.
Growing Object-Oriented Software, Guided by Tests presents such a new perspective. What if software wasnt made, like we make a paper airplanefinish folding it and fly it away? What if, instead, we treated software more like a valuable, productive plant, to be nurtured, pruned, harvested, fertilized, and watered? Traditional farmers know how to keep plants productive for decades or even centuries. How would software development be different if we treated our programs the same way?
I am most impressed by how this book presents both the philosophy and mechanics of such a shift in perspective. It is written by practitioners who codeand teach others to codewell. From it you can learn both how to program to sustain productivity and how to look at your programs anew.
The style of test-driven development presented here is different from what I practice. I cant yet articulate the difference, but I have learned from the clear, confident presentation of the authors techniques. The diversity of dialects has given me a new source of ideas to further refine my own development. Growing Object-Oriented Software, Guided by Tests, presents a coherent, consistent system of development, where different techniques support each other.
I invite you to read Growing Object-Oriented Software, Guided by Tests, to follow along with the examples, to learn how the authors think about programming and how they program. The experience will enrich your software development style, help you programand, just as important, see your programs differently.
Preface
What Is This Book About?
This book is a practical guide to the best way weve found to write object-oriented software: test-driven development (TDD). It describes the processes we follow, the design principles we strive for, and the tools we use. Its founded on our decades of experience, working with and learning from some of the best programmers in the world.
Within the book, we address some of the questions and confusions we see coming up on project after project. How do I fit test-driven development into a software project? Where do I start? Why should I write both unit and end-to-end tests? What does it mean for tests to drive development? How do I test