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 will 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 is important to understand some of the difficulties associated with it as well as considering 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 are designing the interface to our code. Each of the test stages helps us consider an aspect of software design, as illustrated by the following diagram:

Get hands-on with 1200+ tech skills courses.