Foreword xiii
Preface xix
Acknowledgments xxix
About the Author xxxi
Part I: Core Techniques 1
Chapter 1: Thinking Test-Driven 3
The Safety Net 4
Units of Behavior 4
Behavioral Boundaries 6
A Taste of TDD 9
The Future of Test-Driven Development 14
Summary 20
Chapter 2: Basic Moves 21
The TDD Flowchart 21
Thinking in Tests 23
Three Basic Techniques 26
Requests, Tasks, and a To-Do List 26
Exercise Walk-Through 30
Summary 45
Chapter 3: Build upon Existing Behavior 47
Next Steps 47
Improving the Tests 53
Refactoring the Tests 55
Removing the Symptomless Defect 57
Triangulating Away Side Effects 60
A Picture Is Worth a Thousand Words 62
Combining Behaviors 66
Summary 71
Chapter 4: Exceptional Behaviors 73
Raising/Throwing 73
A Test That Passes When the Code "Fails" 75
External Exceptions 77
Summary 78
Chapter 5: Sustaining a Test-Driven Practice 79
Attributes of a Good Unit Test 80
Where to Start 83
What to Test 88
When Code Is Difficult to Test 96
Test Smells and Refactorings 97
Other Common Testing Challenges 136
How to Test a Private
Summary 138
Part II: Ancillary Practices 139
Chapter 6: Test Doubles 141
The Trouble with Dependencies 142
A Test Double Taxonomy 143
Additional Recommendations 153
Summary: Use with Care 160
Chapter 7: Testing Legacy Code 163
Characterization Testing 165
Other Considerations 177
Introduce Virtualizing Proxy 180
Summary: The Complete Toolbox 186
Part III: Return on Investment 189
Chapter 8: The Black Swans 191
The Agilist's Dilemma 192
The Three Levels of Value 193
The Black Swan User Stories 195
Taming the Black Swans 204
Summary 205
Appendix: Exercises 207
Index 213