Skip to content

Instantly share code, notes, and snippets.

@mradbourne
Last active September 25, 2023 10:17
Show Gist options
  • Save mradbourne/f82f29e63597b7f85a12133506daa868 to your computer and use it in GitHub Desktop.
Save mradbourne/f82f29e63597b7f85a12133506daa868 to your computer and use it in GitHub Desktop.
MF2 tests as Gherkin
Feature: Multiple selectors
Background:
Given the username is "Matt"
And the source is:
"""
match {$photoCount :number} {$userGender :equals}
when 1 masculine {{$userName} added a new photo to his album.}
when 1 feminine {{$userName} added a new photo to her album.}
when 1 * {{$userName} added a new photo to their album.}
when * masculine {{$userName} added {$photoCount} photos to his album.}
when * feminine {{$userName} added {$photoCount} photos to her album.}
when * * {{$userName} added {$photoCount} photos to their album.}
"""
Scenario: One item - male
When the message is resolved with params:
| key | value |
| photoCount | 1 |
| userGender | masculine |
Then the string output is "Matt added a new photo to his album."
Scenario: One item - female
When the message is resolved with params:
| key | value |
| photoCount | 1 |
| userGender | feminine |
Then the string output is "Matt added a new photo to her album."
Scenario: One item - other
When the message is resolved with params:
| key | value |
| photoCount | 1 |
| userGender | other |
Then the string output is "Matt added a new photo to their album."
Scenario: Multiple items - male
When the message is resolved with params:
| key | value |
| photoCount | 2 |
| userGender | masculine |
Then the string output is "Matt added 2 photos to his album."
Scenario: Multiple items - female
When the message is resolved with params:
| key | value |
| photoCount | 2 |
| userGender | feminine |
Then the string output is "Matt added 2 photos to her album."
Scenario: Multiple items - other
When the message is resolved with params:
| key | value |
| photoCount | 2 |
| userGender | other |
Then the string output is "Matt added 2 photos to their album."

Advantages

  • Legibility (compared with json, yaml, toml)
  • Separation of test cases and implementation
    • It is easy to utilise regex in step definitions to check param types in the Gherkin
  • Good first-party support from Cucumber across programming languages
  • Tried and tested
  • MIT license (for Gherkin syntax, cucumber-js, cucumber-cpp and cucumber-jvm)

Challenges

  • Providing structured data in arguments is less convenient
    • We can parse strings as structured data in step definitions
    • Will tabular data cater for the majority of cases?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment