Software tests are written as sequences of steps that do things and then check the results of what’s been done. Complete test suites--sets of test cases that fully cover normal, alternate, and exception scenarios--include many variations on a basic scenario. To produce good, complete tests, a tester needs to have a consistent format for writing tests that includes a mechanism for identifying the points where variations can occur.
One authoring style that's gaining in popularity is known by names such as "behavior-driven development" (BDD), “test-driven development” (TDD), or "acceptance-test driven development" (ATDD). Regardless of what the format is called, tests are written as sequences of preconditions, actions, and results. A language called Gherkin (sometimes referred to as "Cucumber") can be used for writing the details of individual scenarios. Gherkin scenarios are divided into sequences of Given, When, and Then sections. Here's an example for just one step in adding a new expense report, specifically the step on which the user enters a date and a number of miles driven:
preconditions |
Given |
a logged in manager is on the Create New Project page |
inputs and actions |
When |
the manager enters a good project name and the manager enters a non-blank description and the manager clicks the Create New Project button |
expected results |
Then |
the new project is created and the manager is returned to his My Projects page and the new project appears on the My Projects page |
The advantage of the BDD approach is that it can normalize the steps in the activity; specifically,
- each step begins at a particular place where certain things are true ("preconditions")
- once the preconditions are verified, certain actions (entering data, making selections, clicking buttons) are performed
- the actions take the user to a new place where certain expected results can be verified
Applying this to the original procedure results in a more regular and a more detailed test:
|
Given the manager wants to add a new project to TAME When the manager opens a web browser to the TAME homepage Then the TAME homepage is displayed. |
|
Given the manager is on the TAME homepage When the manager clicks the Log in link Then the Log in page is displayed |
|
Given the manager is on the Log in page And no one is currently logged in When the manager enters his user ID And the manager enters his correct password And the manager clicks "Log in" Then the manager is taken to his My Projects page And the page displays all of the projects the manager manages And the page displays all of the projects the manager belongs to but does not manage |
|
|
|
|
|
Given a manager is on his My Projects page When the manager clicks the Create a New Project link Then the manager is taken to the New Project page. |
|
Given a logged in manager is on the Create New Project page When the manager enters a good project name And the manager enters a non-blank description And the manager clicks the Create New Project button Then the new project is created And the manager is returned to his My Projects page And the new project appears on the My Projects page |
|
|
|
Given a logged in manager is on his My Projects page When the manager clicks the Log Out button Then the manager is returned to the TAME homepage And the manager is logged out |
|