As long as we write tests, what’s the big deal about writing them “first” rather than “last?” Let’s explore that question.
The video looks a lot better on YouTube than it does here. Try https://youtu.be/Bf89rd0o5-0.
When we’re conscientious about writing examples before production code, and we drive all our production code from executable examples, we can enjoy several benefits:
- Helps us remember details and not overlook things
- Helps us avoid over-engineering or going too far with our design
- Helps us keep the design simple
- Provides a safety net for experimenting with different implementations
- Provides a safety net for refactoring
- Gives us frequent positive feedback so we don’t feel beaten down at the end of the day
- Provides executable low-level documentation of everything the application does
- Makes it easier to locate the source of bugs; keeps us out of the debugger for the most part
- Creates a regression test suite as a side-effect of writing the examples that drive the design
- Equally useful for emergent design and up-front design, and for greenfield development as well as enhancements and bug fixes