Skip to main content
Version: shouty

The BDD Cycle

Start with a failing test​

Can you work out how to run SpecFlow so that it executes the scenarios in the feature file? Run the tests. You should see a mixture of passing and failing SpecFlow scenarios and programmer tests.

Questions​

1. What is the name of the passing scenario?​

Show answer

InRangeShoutIsHeard

2. What is the name of the failing scenario?​

Show answer

OutOfRangeShoutIsNotHeard

3. What is the name of the passing programmer test?​

Show answer

ItCalculatesTheDistanceFromItself

4. What is the name of the failing programmer test?​

Show answer

ItCalculatesTheDistanceFromAnotherCoordinateAlongXAxis

5. How would you explain to your product owner what is wrong with Shouty, from what you see in the test results?​

Show answer

Discuss amongst your group.

Red, Green, Refactor​

Now we have a failing programmer test and a failing scenario. We need to get them both passing.

1. Modify the application code​

Write the production code that will make the failing programmer test pass. You should not need to edit the feature file, the step definition file or the programmer test file.

HINT

There’s a commented-out line in the Coordinate implementation that will get the programmer test passing.

2. Run the tests again​

Run all the tests again. Both the programmer tests should be passing, but one of the scenarios should still be failing.

DISCUSS

Does the code you have just uncommented look like a complete solution?

3. Add a unit test before making the scenario pass​

Open the programmer test file and uncomment the programmer test that is commented out.

Run all the tests again.

DISCUSS
  • Which programmer test(s) are failing?
  • Which scenario(s) are failing?
  • Can you see what changes you have to make to get the new programmer test to pass?

4. Modify the application code to make both tests pass​

HINT

Use Pythagoras' theorem.

Keep working and running all the tests until you see all the programmer tests, steps and scenarios pass.

Where are we in the BDD cycle?​

Now that we've got everything passing we've moved into new territory in the BDD Cycle.

Use the diagram and labels below to answer the questions that follow.

BDD Process

  1. Decide the next user story to work on
  2. Use concrete examples to explore and discover the acceptance criteria for the user story
  3. Formulate a concrete example as a scenario
  4. Automate a scenario and see it fail
  5. Write a programmer test and see it fail
  6. Write enough code to make the programmer test pass
  7. Refactor to clean up the code
  8. Manual exploratory testing
  9. Release to production

Questions​

1. Where are we now?​

Show answer

We are at step 6, writing enough code to make the programmer test pass.

Prior to this we began at step 4, automating a scenario and seeing it fail. Then we did step 5, writing a programmer test and seeing it fail.

2. What do we need to do next?​

Show answer

Step 7. We must refactor our code and ensure our programmer tests and scenarios still pass.

DISCUSS

Are you satisfied with your solution? Is there anything you would change?

In the next section you'll have a chance to refactor some of the code and learn about step definition arguments.