chapter three

3 What is an Example?

 

This chapter covers

  • The structure and purpose of a concrete example
  • How to know when you have enough examples
  • How rules and examples work together
  • Focusing each example on a single rule

In the previous chapters, we explored the role of examples in a BDD approach. You may have wondered: “Are examples really enough to specify a story? How many examples do we need to specify a story?”

In this chapter, we’re going to answer these questions.

3.1 How hard is concrete?

We all know what a real life example looks like, but for them to be the foundation of a reliable software specification that unambiguously illustrates how a system should behave, they need to be concrete. It’s best to think of an example as being an artifact divided into 3 parts - context, action and outcome, as shown in figure 3.1 - and it can be helpful to think of these in the reverse order.

Figure 3.1 Anatomy of an example

The outcome is a description of the state of the system after the behavior we’re interested in has taken place. It should contain enough detail for us to check that the system has behaved according to our expectations.

The action is the event that triggers the behavior we’re interested in to take place. It might be some action by a user, but equally it might be an input from another system, a scheduled job, or any other stimulus that can cause the system to react.

3.2 Is all that concrete essential?

3.3 Do we need more examples?

3.4 Why stop now?

3.5 Rules vs. examples

3.6 My example illustrates multiple rules!

3.7 Summary