oopbddbehatgherkinnon-repetitive

Flexibility of scenarios in Gherkin.


I looking for mechanism that will allow to build more flexible scenarios.

For example for these two very similar scenarios that test existence of records in database:

Scenario Outline: Testing query with 1 attribute with these 2 record in and another 2 out of result
  Given I'm connected to <db> database
  When I select <query> from database
  Then Result should contain fields:
    | <row>  |
    | <yes1> |
    | <yes2> |
  And Result should not contain fields:
    | <row> |
    | <no1> |
    | <no2> |

  Examples:
    | db | row   | yes1 | yes2 | no1  | no2  | query                                                            |
    | 1  | model | 1013 | 1006 | 1012 | 1007 | "SELECT model FROM pc WHERE speed >= 3.0;"                       |
    | 1  | maker | E    | A    | C    | H    | "SELECT maker FROM product NATURAL JOIN laptop WHERE hd >= 100;" |

Scenario Outline: Testing query with 2 attributes with these 2 record in and another 2 out of result
  Given I'm connected to <db> database
  When I select <query> from database
  Then Result should contain fields:
    | <rowA>  | <rowB>  |
    | <yes1A> | <yes1B> |
    | <yes2A> | <yes2B> |
  And Result should not contain fields:
    | <rowA> | <rowB> |
    | <no1A> | <no1B> |
    | <no2A> | <no2B> |
  Examples:
    | db | rowA  | rowB    | yes1A  | yes1B | yes2A | yes2B | no1A    | no1B | no2A | no2B | query                              |
    | 1  | model | price   | 1004   | 649   | 2007  | 1429  | 2004    | 1150 | 3007 | 200  | "SELECT model,price FROM product"  |
    | 2  | name  | country | Yamato | Japan | North | USA   | Repulse | Brit | Cal  | USA  | "SELECT name, country FROM clases" |

I would like to be able to write one scenario with general number of attributes. It would be great if number of tested rows will not be determined too.

My dream is to write only one general scenario:

Testing query with N attribute with these M record in and another L out of result

How to do this in Gherkin? Is it possible with any hacks?


Solution

  • The short answer is, No. Gherkin is not about flexibility, Gherkin is about concrete examples. Concrete example are everything except flexible.

    A long answer is:

    You are describing a usage of Gherkin as a test tool. The purpose with Gherkin is, however, not to test things. The purpose with Gherkin is to facilitate communication between development and the stakeholders that want a specific behaviour.

    If you want to test something, there are other tooling that will support exactly what you want. Any test framework will be usable. My personal choice would be JUnit since I work mostly with Java.

    The litmus test for deciding on the tooling is, who will have to be able to understand this?

    If the answer is non techs, I would probably use Gherkin with very concrete examples. Concrete examples are most likely not comparing things in a database. Concrete examples tend to describe external, observable behaviour of the system.

    If the answer is developers, then I would probably use a test framework where I have access to a programming language. This would allow for the flexibility you are asking for.

    In your case, you are asking for a programming language. Gherkin and Cucumber are not the right tools in your case.