SPECIAL OFFERS
Keep up with new releases and promotions. Sign up to hear from us.
Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
Also available in other formats.
This is a working draft of a pre-release book. It is available before the published date as part of the Rough Cuts service.
Foreword by Kent Beck
"The authors of this book have led a revolution in the craft of programming by controlling the environment in which software grows.” --Ward Cunningham
“At last, a book suffused with code that exposes the deep symbiosis between TDD and OOD. This one's a keeper.” --Robert C. Martin
“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
Test-Driven Development (TDD) is now an established technique for delivering better software faster. TDD is based on a simple idea: Write tests for your code before you write the code itself. However, this "simple" idea takes skill and judgment to do well. Now there's a practical guide to TDD that takes you beyond the basic concepts. Drawing on a decade of experience building real-world systems, two TDD pioneers show how to let tests guide your development and “grow” software that is coherent, reliable, and maintainable.
Steve Freeman and Nat Pryce describe the processes they use, the design principles they strive to achieve, and some of the tools that help them get the job done. Through an extended worked example, you’ll learn how TDD works at multiple levels, using tests to drive the features and the object-oriented structure of the code, and using Mock Objects to discover and then describe relationships between objects. Along the way, the book systematically addresses challenges that development teams encounter with TDD--from integrating TDD into your processes to testing your most difficult features. Coverage includes
• Implementing TDD effectively: getting started, and maintaining your momentum
throughout the project
• Creating cleaner, more expressive, more sustainable code
• Using tests to stay relentlessly focused on sustaining quality
• Understanding how TDD, Mock Objects, and Object-Oriented Design come together
in the context of a real software development project
• Using Mock Objects to guide object-oriented designs
• Succeeding where TDD is difficult: managing complex test data, and testing persistence
and concurrency
Foreword xv
Preface xvii
Acknowledgments xxi
About the Authors xxiii
PART I: INTRODUCTION 1
Chapter 1: What Is the Point of Test-Driven Development? 3
Software Development as a Learning Process 3
Feedback Is the Fundamental Tool 4
Practices That Support Change 5
Test-Driven Development in a Nutshell 6
The Bigger Picture 7
Testing End-to-End 8
Levels of Testing 9
External and Internal Quality 10
Chapter 2: Test-Driven Development with Objects 13
A Web of Objects 13
Values and Objects 13
Follow the Messages 14
Tell, Don’t Ask 17
But Sometimes Ask 17
Unit-Testing the Collaborating Objects 18
Support for TDD with Mock 19
Chapter 3: An Introduction to the Tools 21
Stop Me If You’ve Heard This One Before 21
A Minimal Introduction to JUnit 4 21
Hamcrest Matchers and assertThat() 24
jMock2: Mock Objects 25
PART II: THE PROCESS OF TEST-DRIVEN DEVELOPMENT 29
Chapter 4: Kick-Starting the Test-Driven Cycle 31
Introduction 31
First, Test a Walking Skeleton 32
Deciding the Shape of the Walking Skeleton 33
Build Sources of Feedback 35
Expose Uncertainty Early 36
Chapter 5: Maintaining the Test-Driven Cycle 39
Introduction 39
Start Each Feature with an Acceptance Test 39
Separate Tests That Measure Progress from Those That Catch Regressions 40
Start Testing with the Simplest Success Case 41
Write the Test That You’d Want to Read 42
Watch the Test Fail 42
Develop from the Inputs to the Outputs 43
U