Adding Tests First

Explore the significance of test-first methodology as a design tool in TDD, highlighting its role in uncovering design opportunities, forming executable specifications, and aiding continuous delivery.

In this lesson, we’ll review the trade-offs of adding a test first before writing the production code to make it pass. Previous chapters have followed a test-first approach to writing code. We write a test before writing production code to make that test pass. This is a recommended approach, but it’s important to understand some of the difficulties associated with it as well as consider its benefits.

Test-first is a design tool

The most important benefit of writing tests first is that a test acts as a design aid. As we decide what to write in our test, we’re designing the interface to our code. Each of the test stages helps us consider an aspect of software design, as shown by the following illustration:

Get hands-on with 1400+ tech skills courses.