Skip to content

Using BDD and Cucumber in Squash AUTOM - Writing test cases

Writing the test cases

Annita
Squash TM administrator
Pravash
Product owner
Fabrice
Functional tester
Antonine
Automatician
Set up Squash TM
Write requirements
Write test cases
Transmit test cases
Get test cases
Automate test cases
Deliver automated test cases
Indicate automation is performed
Run automated tests

During refinement sessions, Pravash explains to the whole team (Scrum master, developers, and Fabrice) the features he wants to get in the product.
For each feature, the developers and Fabrice ask for details to Pravash (nominal cases, error cases, boundary cases…). Then, the team defines together one or more use cases and draft them using the Gherkin syntax. This ensures that everybody share the same understanding of what needs to be implemented and that this understanding is capitalized.

An overview of the Gherkin syntax

  • Given (Arrange): Describes a prerequisite, a.k.a. a precondition, for the scenario to be applicable.
    All the prerequisites define the initial state (or at least the relevant part of the initial state) of the system before the start of the use case.
  • When (Act): Describes an action taken during the test.
    Actions are performed in the specified order.
  • Then (Assert): Describes an outcome, a.k.a. a postcondition, that should be fulfilled at the end of the test.
    All the outcomes define the expected final state (or at least the relevant part of the final state) of the system after the end of the use case.

Some conjunctions can be used to avoid repeating the previous words (they have the same meaning as repeating the word):

  • And
  • But

Examples:

Scenario: A user withdraws money from his bank account
    Given Eric has a valid basic Debit card  
    And his account balance is $100  
    When he inserts his card  
    And he withdraws $45  
    Then the ATM should give $45  
    And the ATM returns his card
    And his account balance is $55

Scenario: A user attempts to withdraw more money than he has in his account
    Given Vsevolod has a valid basic Debit card  
    And his account balance is $20  
    When he inserts his card  
    And he withdraws $40  
    Then the ATM displays an error  
    And the ATM returns his card
    But his account balance remains $20

Doc Strings can be used to define a large piece of text. They are delimited by three double-quotes.
Example:

Then the ATM displays the following error message
 """
 Refused withdraw
 ================
 Your Debit card does does allow you to withdraw more money than your current account balance.
 Please, contact your bank councillor.
 """

Data Tables can be used to define a list of values in an action.
Example:

Given the Debit cards exist:
  | name     | allowed overdraw | max overdraw duration (days) |
  | basic    | $0               | 0                            |
  | gold     | $500             | 15                           |
  | platinum | $3000            | 42                           |

It is possible to group scenarios having the same actions, but different values by using Scenario Outline and placeholders between < and >.
Example:

Scenario Outline: A user withdraws money from an ATM  
    Given <Name> has a valid basic Debit card  
    And his account balance is <OriginalBalance>  
    When he inserts his card    
    And he withdraws <WithdrawalAmount>  
    Then the ATM should give <WithdrawalAmount>  
    And the ATM returns his card
    And his account balance is <NewBalance>

    Examples:
      | Name   | OriginalBalance | WithdrawalAmount | NewBalance |
      | Eric   | 100             | 45               | 55         |
      | Gaurav | 100             | 40               | 60         |
      | Ed     | 1000            | 200              | 800        |

Fabrice records these Gherkin scenarios as test cases in Squash TM and indicates their traceability to the requirements as defined in the Squash TM documentation:

test case definition

test case definition

test case definition

Transmitting the test cases

Annita
Squash TM administrator
Pravash
Product owner
Fabrice
Functional tester
Antonine
Automatician
Set up Squash TM
Write requirements
Write test cases
Transmit test cases
Get test cases
Automate test cases
Deliver automated test cases
Indicate automation is performed
Run automated tests

Once a test case has been reviewed and approved (see Squash TM documentation), Fabrice flags it as elligible for automation (see Squash TM documentation) and, optionally, defines an automation priority. He can now transmit the test case by clicking on the arrow:

test case transmission

The test case transmission has two effects:

  • the Cucumber feature file is generated and is pushed to the remote Git repository a few minutes later;
  • the test case appears in the Automation Workspace.
Back to top