Search⌘ K
AI Features

We Don’t Know What to Test Until We Write the Code

Explore how to determine what to test when practicing test-driven development (TDD). Understand the use of spikes to experiment with design before writing production code and how TDD guides better software structure and cleaner interfaces. Learn to make informed design decisions while developing testable, maintainable code.

A great frustration for TDD learners is knowing what to test without having written the production code beforehand. This is another criticism that has merit. In this case, once we understand the issue that developers face, we can see that the solution is a technique we can apply to our workflow, not a framing of thinking.

Understanding the difficulty of starting with testing

To an extent, it’s natural to think about how we implement code. It’s how we learn, after all. We write System.out.println("Hello, World!"); instead of thinking up some structure to place around the famous line. Small programs and utilities work just fine when we write them as linear codes, similar to a shopping list of instructions.

We begin to face difficulties as ...