Growing Object-Oriented Software, Guided by Tests (Addison-Wesley Signature Series)

Paperback
from $0.00

Author: Steve Freeman

ISBN-10: 0321503627

ISBN-13: 9780321503626

Category: Object - Oriented Programming

Search in google:

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 FeathersTest-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 momentumthroughout 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 togetherin 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 persistenceand concurrency

Foreword xvPreface xviiAcknowledgments xxiAbout the Authors xxiiiPART I: INTRODUCTION 1Chapter 1: What Is the Point of Test-Driven Development? 3Software Development as a Learning Process 3Feedback Is the Fundamental Tool 4Practices That Support Change 5Test-Driven Development in a Nutshell 6The Bigger Picture 7Testing End-to-End 8Levels of Testing 9External and Internal Quality 10Chapter 2: Test-Driven Development with Objects 13A Web of Objects 13Values and Objects 13Follow the Messages 14Tell, Don’t Ask 17But Sometimes Ask 17Unit-Testing the Collaborating Objects 18Support for TDD with Mock 19Chapter 3: An Introduction to the Tools 21Stop Me If You’ve Heard This One Before 21A Minimal Introduction to JUnit 4 21Hamcrest Matchers and assertThat() 24jMock2: Mock Objects 25PART II: THE PROCESS OF TEST-DRIVEN DEVELOPMENT 29Chapter 4: Kick-Starting the Test-Driven Cycle 31Introduction 31First, Test a Walking Skeleton 32Deciding the Shape of the Walking Skeleton 33Build Sources of Feedback 35Expose Uncertainty Early 36Chapter 5: Maintaining the Test-Driven Cycle 39Introduction 39Start Each Feature with an Acceptance Test 39Separate Tests That Measure Progress from Those That Catch Regressions 40Start Testing with the Simplest Success Case 41Write the Test That You’d Want to Read 42Watch the Test Fail 42Develop from the Inputs to the Outputs 43Unit-Test Behavior, Not Methods 43Listen to the Tests 44Tuning the Cycle 45Chapter 6: Object-Oriented Style 47Introduction 47Designing for Maintainability 47Internals vs. Peers 50No And’s, Or’s, or But’s 51Object Peer Stereotypes 52Composite Simpler Than the Sum of Its Parts 53Context Independence 54Hiding the Right Information 55An Opinionated View 56Chapter 7: Achieving Object-Oriented Design 57How Writing a Test First Helps the Design 57Communication over Classification 58Value Types 59Where Do Objects Come From? 60Identify Relationships with Interfaces 63Refactor Interfaces Too 63Compose Objects to Describe System Behavior 64Building Up to Higher-Level Programming 65And What about Classes? 67Chapter 8: Building on Third-Party Code 69Introduction 69Only Mock Types That You Own 69Mock Application Objects in Integration Tests 71PART III: A WORKED EXAMPLE 73Chapter 9: Commissioning an Auction Sniper 75To Begin at the Beginning 75Communicating with an Auction 78Getting There Safely 79This Isn’t Real 81Chapter 10: The Walking Skeleton 83Get the Skeleton out of the Closet 83Our Very First Test 84Some Initial Choices 86Chapter 11: Passing the First Test 89Building the Test Rig 89Failing and Passing the Test 95The Necessary Minimum 102Chapter 12: Getting Ready to Bid 105An Introduction to the Market 105A Test for Bidding 106The AuctionMessageTranslator 112Unpacking a Price Message 118Finish the Job 121Chapter 13: The Sniper Makes a Bid 123Introducing AuctionSniper 123Sending a Bid 126Tidying Up the Implementation 131Defer Decisions 136Emergent Design 137Chapter 14: The Sniper Wins the Auction 139First, a Failing Test 139Who Knows about Bidders? 140The Sniper Has More to Say 143The Sniper Acquires Some State 144The Sniper Wins 146Making Steady Progress 148Chapter 15: Towards a Real User Interface 149A More Realistic Implementation 149Displaying Price Details 152Simplifying Sniper Events 159Follow Through 164Final Polish 168Observations 171Chapter 16: Sniping for Multiple Items 175Testing for Multiple Items 175Adding Items through the User Interface 183Observations 189Chapter 17: Teasing Apart Main 191Finding a Role 191Extracting the Chat 192Extracting the Connection 195Extracting the SnipersTableModel 197Observations 201Chapter 18: Filling In the Details 205A More Useful Application 205Stop When We’ve Had Enough 205Observations 212Chapter 19: Handling Failure 215What If It Doesn’t Work? 215Detecting the Failure 217Displaying the Failure 218Disconnecting the Sniper 219Recording the Failure 221Observations 225PART IV: SUSTAINABLE TEST-DRIVEN DEVELOPMENT 227Chapter 20: Listening to the Tests 229Introduction 229I Need to Mock an Object I Can’t Replace (without Magic) 230Logging Is a Feature 233Mocking Concrete Classes 235Don’t Mock Values 237Bloated Constructor 238Confused Object 240Too Many Dependencies 241Too Many Expectations 242What the Tests Will Tell Us (If We’re Listening) 244Chapter 21: Test Readability 247Introduction 247Test Names Describe Features 248Canonical Test Structure 251Streamline the Test Code 252Assertions and Expectations 254Literals and Variables 255Chapter 22: Constructing Complex Test Data 257Introduction 257Test Data Builders 258Creating Similar Objects 259Combining Builders 261Emphasizing the Domain Model with Factory Methods 261Removing Duplication at the Point of Use 262Communication First 264Chapter 23: Test Diagnostics 267Design to Fail 267Small, Focused, Well-Named Tests 268Explanatory Assertion Messages 268Highlight Detail with Matchers 268Self-Describing Value 269Obviously Canned Value 270Tracer Object 270Explicitly Assert That Expectations Were Satisfied 271Diagnostics Are a First-Class Feature 271Chapter 24: Test Flexibility 273Introduction 273Test for Information, Not Representation 274Precise Assertions 275Precise Expectations 277“Guinea Pig” Objects 284PART V: ADVANCED TOPICS 287Chapter 25: Testing Persistence 289Introduction 289Isolate Tests That Affect Persistent State 290Make Tests Transaction Boundaries Explicit 292Testing an Object That Performs Persistence Operations 294Testing That Objects Can Be Persisted 297But Database Tests Are S-l-o-w! 300Chapter 26: Unit Testing and Threads 301Introduction 301Separating Functionality and Concurrency Policy 302Unit-Testing Synchronization 306Stress-Testing Passive Objects 311Synchronizing the Test Thread with Background Threads 312The Limitations of Unit Stress Tests 313Chapter 27: Testing Asynchronous Code 315Introduction 315Sampling or Listening 316Two Implementations 318Runaway Tests 322Lost Updates 323Testing That an Action Has No Effect 325Distinguish Synchronizations and Assertions 326Externalize Event Sources 326Afterword: A Brief History of Mock Objects 329Appendix A: jMock2 Cheat Sheet 335Appendix B: Writing a Hamcrest Matcher 343Bibliography 347Index 349