Working Effectively with Unit Tests
Last updated on 2015-01-26
About the Book
tl;dr: This book details my strong opinions on the best way to test, while acknowledging alternative styles and various contexts in which tests are written. Whether you prefer my style or not, this book will help you write better Unit Tests.
From the Preface:
Over a dozen years ago I read Refactoring for the first time; it immediately became my bible. While Refactoring isn’t about testing, it explicitly states: If you want to refactor, the essential precondition is having solid tests. At that time, if Refactoring deemed it necessary, I unquestionably complied. That was the beginning of my quest to create productive unit tests.
Throughout the 12+ years that followed reading Refactoring I made many mistakes, learned countless lessons, and developed a set of guidelines that I believe make unit testing a productive use of programmer time. This book provides a single place to examine those mistakes, pass on the lessons learned, and provide direction for those that want to test in a way that I’ve found to be the most productive.
The book does touch on some theory and definition, but the main purpose is to show you how to take tests that are causing you pain and turn them into tests that you're happy to work with. If you're like me and enjoy examples, you can take a (free) look at Chapter 1 right now. The foreword, preface, and first 2 chapters are available within The Sample.
Reviews are available at review.wewut.com.
"I trust Jay Fields' opinions about how to write good programmer tests, and so should you." -- J. B. Rainsberger @jbrains
"Buy this. That is all." -- Dan North @tastapod
"This book is a breath of fresh air! Excellent work! The evolution of a hairy test to something really clean is elegant. I wish more people wrote tests like this. Having a book to point people at will really help." -- Joe Walnes @joewalnes
"I just read through what Jay Fields has so far, and it is looking to be really great. I highly recommend it..." -- Corey Haines @coreyhaines
5 Copy Package
This package is for up to 5 copies of Working Effectively with Unit Tests
15 Copy Package
This package is for up to 15 copies of Working Effectively with Unit Tests.
50 Copy Package
This package is for up to 50 copies of Working Effectively with Unit Tests
200 Copy Package
This package is for up to 200 copies of Working Effectively with Unit Tests
Unit Testing, a First Example
- Thoughts on our Tests
- The Domain Code
- Moving Towards Readability
- Replace Loop with Individual Tests
- Expect Literals
- Inline Setup
- Replace ObjectMother with DataBuilder
- Comparing the Results
- Final Thoughts on our Tests
Types of Tests
- State Verification
- Behavior Verification
- Unit Test
- Solitary Unit Test
- Sociable Unit Test
- Continuing with Examples From Chapter 1
- Final Thoughts, Again
- One Assertion Per Test
- Implementation Overspecification
- Assert Last
- Expect Literals
- Negative Testing
Improving Test Cases
- Too Much Magic
- Inline Setup
- Test Names
Improving Test Suites
- Separating The Solitary From The Sociable
- Questionable Tests
- Custom Assertions
- Global Definition
- Broad Stack Tests
- Test Pyramid
- Final Thoughts On ROI
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...