O'Reilly logo

Beyond Legacy Code by David Scott Bernstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required