Include both narrow and end-to-end tests

Across an entire implementation, there is typically a need to have tests that are narrow in focus as well as tests that cover broad end-to-end functionality. The general guideline is:

  • If you are testing a specific unit of functionality, such as form inference during a submission, write a scenario with a narrow scope that tests the specific functionality only.
  • If you are testing a user's journey through a series of screens or steps in a wizard, write a scenario with a broad scope that tests the flow end-to-end.

The best practice is to write a combination of tests with narrow scope and broad scope. The two extremes compliment each other. Narrow tests ensure the several small pieces of functionality work as intended, and they can be run quickly. On the other hand, end-to-end tests take longer to run, but they are useful to make sure that all the small pieces of functionality work as intended when they are combined together in a single user flow.

Multiple Then sections

All scenarios are limited to a single Given section.

Scenarios with a narrow scope typically have a single When section followed by a single Then section.

An end-to-end test may have multiple When sections, each followed by its own Then section. This structure is used to help define the state the system should be at important points during the end-to-end flow.