#resource/book
Author: [[Meszaros, Gerard]]
[Amazon](https://www.amazon.com/xUnit-Test-Patterns-Refactoring-Code/dp/0131495054)
Automated testing is a cornerstone of agile development. An effective testing strategy will deliver new functionality more aggressively, accelerate user feedback, and improve quality. However, for many developers, creating effective automated tests is a unique and unfamiliar challenge.
**_xUnit Test Patterns_** is the definitive guide to writing automated tests using xUnit, the most popular unit testing framework in use today. [[Agile]] coach and test automation expert Gerard Meszaros describes 68 proven patterns for making tests easier to write, understand, and maintain. He then shows you how to make them more robust and repeatable--and far more cost-effective.
Loaded with information, this book feels like three books in one. The first part is a detailed tutorial on test automation that covers everything from test strategy to in-depth test coding. The second part, a catalog of 18 frequently encountered "test smells," provides trouble-shooting guidelines to help you determine the root cause of problems and the most applicable patterns. The third part contains detailed descriptions of each pattern, including refactoring instructions illustrated by extensive code samples in multiple programming languages.
Topics covered include
- Writing better tests--and writing them faster
- The four phases of automated tests: fixture setup, exercising the system under test, result verification, and fixture teardown
- Improving test coverage by isolating software from its environment using Test Stubs and Mock Objects
- Designing software for greater testability
- Using test "smells" (including code smells, behavior smells, and project smells) to spot problems and know when and how to eliminate them
- [[Refactoring]] tests for greater simplicity, robustness, and execution speed
This book will benefit developers, managers, and testers working with any agile or conventional development process, whether doing test-driven development or writing the tests last. While the patterns and smells are especially applicable to all members of the xUnit family, they also apply to next-generation behavior-driven development frameworks such as RSpec and JBehave and to other kinds of test automation tools, including recorded test tools and data-driven test tools such as Fit and FitNesse.
Visual Summary of the Pattern Language
Foreword
Preface
Acknowledgments
Introduction
Refactoring a Test
### PART I: The Narratives
Chapter 1 A Brief Tour
- [[The Simplest Test Automation Strategy That Could Possibly Work]]
Chapter 2 [[Test Smells]]
Chapter 3 [[Goals of Test Automation]]
Chapter 4 [[Philosophy of Test Automation]]
Chapter 5 [[Principles of Test Automation]]
Chapter 6 [[Test Automation Strategy]]
- What's Strategic?
- Which Kind of Tests Should We Automate?
- Per-Functionality Tests
- Cross Functionality Tests
- Which Tools Do We Use to Automate Which Tests?
- [[Test Automation]] Ways and Means
- Introducing xUnit
- The xUnit Sweet Spot
- Which Test Fixture Strategy Do We Use?
- [[What is a Fixture?]]
- [[Major Fixture Strategies]]
- Transient Fresh Fixtures
- Persistent Fresh Fixtures
- Shared Fixture Strategies
- [[How Do We Ensure Testability?]]
- Test Last-At Your Peril
- Design for Testability-Upfront
- Test Driven Testability
- [[Control Points and Observation Points]]
- [[Interaction Styles and Testability Patterns]]
- [[Divide and Test]]
Chapter 7 xUnit Basics
- Common Features
- The Bare Minimum
- Defining Tests
- What's Fixture?
- Defining Suites of Tests
- Running Tests
- Test Results
- Under the xUnit Covers
- Test Commands
- Test Suite Objects
- xUnit in Procedural World
Chapter 8 [[Transient Fixture Management]]
- Test Fixture Terminology
- What Is a Fixture?
- What Is a Fresh Fixture?
- What Is a Transient Fresh Fixture?
- Building Fresh Fixtures
- In-line Fixture Setup
- Delegated Fixture Setup
- Implicit Fixture Setup
- Hybrid Fixture Setup
- Tearing Down Transient Fresh Fixtures
Chapter 9 [[Persistent Fixture Management]]
- Managing Persistent Fresh Fixtures
- What Makes Fixtures Persistent?
- Issues Caused by Persistent Fresh Fixtures
- Tearing Down Persistent Fresh Fixtures
- [[Avoiding the Need for Teardown]]
- [[Dealing with Slow Tests]]
- Managing Shared Fixtures
- Accessing Shared Fixtures
- Triggering Shared Fixture Construction
Chapter 10 [[Result Verification]]
- Making Tests Self-Checking
- Verify State or Behavior?
- [[State Testing]]
- Using Build-in Assertions
- Delta Assertions
- External Result Verification
- [[Verifying Behavior]]
- Procedural Behavior Verification
- Expected Behavior Specification
- [[Reducing Test Code Duplication]]
- Expected Objects
- Custom Assertions
- Outcome-Describing Verification Method
- Parametrized and Data Driven Tests
- [[Avoiding Conditional Test Logic]]
- Eliminating "if" Statements
- Eliminating Loops
- Other Techniques
- Working Backwards, Outside-In
- [[Using Test Driven Development to Write Test Utility Methods]]
- [[Where to Put Reusable Verification Logic?]]
Chapter 11 Using [[Test Double]]
- What are Indirect Inputs and Outputs?
- Why Do We Care about Indirect Inputs?
- Why Do We Care about Indirect Outputs?
- How Do We Control Indirect Inputs?
- How Do We Control Indirect Outputs
- Testing with Doubles
- [[Types of Test Doubles]]
- Providing the Test Double
- Configuring the Test Double
- Installing the Test Double
- Other Uses of Test Doubles
- Endoscopic Testing
- Need-Driven Development
- Speeding Up Fixture Setup
- Speeding Up Test Execution
- Other Considerations
Chapter 12 [[Test Organization]]
- Basic xUnit Mechanisms
- Right-Sizing Test Methods
- Test Methods and Testcase Classes
- Testcase Class per Class
- Testcase Class per Feature
- Testcase Class per Fixture
- Choosing a Test Method Organization Strategy
- [[Test Naming Conventions]]
- [[Organizing Test Suites]]
- Running Groups of Tests
- Running a Single Test
- [[Test Code Reuse]]
- Test Utility Method Locations
- Testcase Inheritance and Reuse
- Test File Organization
- Build-in Self-Test
- Test Packages
- Test Dependencies
Chapter 13 [[Testing with Databases]]
- Why Testing with Databases?
- Issues with Databases
- Testing without Databases
- Testing the Database
- Testing Stored Procedures
- Testing the Data Access Layer
- Ensuring Developer Independence
- Testing with Databases (Again!)
Chapter 14 [[A Roadmap to Effective Test Automation]]
- Test Automation Difficulty
- Roadmap to Highly Maintainable Automated Tests
- Exercise the Happy Path Code
- Verify Direct Outputs of the Happy Path
- Verify Alternative Paths
- Verify Indirect Outputs Behavior
- Optimize Test Execution and Maintenance
### PART II: The Test Smells
Chapter 15 [[Test Smells - Code Smells]]
- Obscure Test
- Conditional Test Logic
- Hard-to-Test Code
- Test Code Duplication
- Test Logic in Production
Chapter 16 [[Test Smells - Behavior Smells]]
- Assertion Roulette
- Erratic Test
- Fragile Test
- Frequent Debugging
- Manual Intervention
- Slow Tests
Chapter 17 [[Test Smells - Project Smells]]
- Buggy Tests
- Developers Not Writing Tests
- High Test Maintenance Cost
- Production Bugs
### PART III: The Patterns
Chapter 18 [[Test Strategy Patterns]]
- Recorded Test
- Scripted Test
- Data-Driven Test
- Test Automation Framework
- Minimal Fixture
- Standard Fixture
- Fresh Fixture
- Shared Fixture
- Back Door Manipulation
- Layer Test
Chapter 19 [[xUnit Basics Patterns]]
- Test Method
- Four-Phase Test
- Assertion Method
- Assertion Message
- Testcase Class
- Test Runner
- Testcase Object
- Test Suite Object
- Test Discovery
- Test Enumeration
- Test Selection
Chapter 20 [[Fixture Setup Patterns]]
- In-line Setup
- Delegated Setup
- Creation Method
- Implicit Setup
- Prebuilt Fixture
- Lazy Setup
- Suite Fixture Setup
- Setup Decorator
- Chained Tests
Chapter 21 [[Result Verification Patterns]]
- [[State Testing]]
- [[Behavior Verification]]
- [[Custom Assertion]]
- [[Delta Assertion]]
- [[Guard Assertion]]
- [[Unfinished Test Assertion]]
Chapter 22 [[Fixture Teardown Patterns]]
- Garbage-Collected Teardown
- Automated Teardown
- In-line Teardown
- Implicit Teardown
Chapter 23 [[Test Double Patterns]]
- Test Double
- Test Stub
- Test Spy
- Mock Object
- Fake Object
- Configurable Test Double
- Hard-Coded Test Double
- Test-Specific Subclass
Chapter 24 [[Test Organization Patterns]]
- Named Test Suite
- Test Utility Method
- Parametrized Test
- Testcase Class per Class
- Testcase Class per Feature
- Testcase Class per Fixture
- Testcase Superclass
- Test Helper
Chapter 25 [[Database Patterns]]
- Database Sandbox
- Stored Procedure Test
- Table Truncation Teardown
- Transaction Rollback Teardown
Chapter 26 [[Design for Testability Patterns]]
- Dependency Injection
- Dependency Lookup
- Humble Object
- Test Hook
Chapter 27 [[Value Patterns]]
- Literal Value
- Derived Value
- Generated Value
- Dummy Object
PART IV: Appendixes
Appendix A Test Refactorings
Appendix B xUnit Terminology
Appendix C xUnit Family Members
Appendix D Test Tools
Appendix E Goals and Principles
Appendix F Smells, Aliases, and Causes
Appendix G Patterns, Aliases, and Variations
Glossary
References
Index