Design the First Failing Test with Bare Production Code

When you’re new to test-driven development, writing the first test can feel counterintuitive. How are you supposed to test something that doesn’t exist?

The answer is to create just enough production code to get the test to compile. By writing the test first, we focus on designing the interface from the point of view of the caller. The test code is the first call site.

The requirements don’t describe the interface. That’s up to us to figure out and depends on the context. With little context to guide us, let’s make some educated guesses. Let’s assume the name of the person won’t change often. But the time of day keeps changing.

Remember from Chapter 6, Manage Difficult Dependencies ...

Get iOS Unit Testing by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.