An Example of Specifying Behaviors Test-First
Let’s walk through an example in detail. This example illustrates how to create the right kind and number of tests for a specific behavior to drive the development of that behavior.
If you’re not a programmer and you don’t read source code, don’t worry. You should be able to understand the gist of what the code is doing if I’ve named things well. Even if you don’t understand exactly how this code works, you’ll certainly get a sense of many things developers must consider when building software.
Let’s say I want to create a Person class that has a name and an age. I am programming in Java using the Eclipse[46] development environment.
Write the Test
I start by writing a test for the happy path:
Get Beyond Legacy Code 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.