Is there any BDD tool for Scala supporting reusable parameterized Gherkin clauses?
I would like to be able to have the ability to use specs like these:
Given number 4 is entered
When "+" is pressed
And number -1 is entered
And "*" is pressed
And number 2 is entered
And "=" is pressed
Then result is 6
And I would like to define fixtures to Gherkin clauses differing by a parameter only once, something like:
scenario("(4+(-1)) * 2 = 6") {
given("number 4 is entered")
when("'+' is pressed")
and("number -1 is entered")
and("'*' is pressed")
and("number 2 is entered")
and("'=' is pressed")
then("result is 0")
}
Given definitions of clauses looking like as follows:
"number $number is entered" {
calculator.enter(number)
}
"'$key' is pressed" {
calculator.press(key)
}
"result is $number" {
assert(calculator.getDisplayedNumber === number)
}
I looked through ScalaTest and Specs manuals but I didn't find such feature. ScalaTest seems to be able to reuse the defined clause in a different scenario, but looks like it is not parameterised.
Do you know some tools that does support what I want, or e.g. some extensions to ScalaTest, or a way to extend it myself with such result?
Select BDD - Gherkin from the Type dropdown. The Gherkin editor appears. Write your test case. Remember not to include Feature or Scenario. Click the image to enlarge it.
There are many advantages of using Gherkin language to write and define the behaviour in your BDD framework. Some of the major ones are mentioned below: 1. Gherkin is simple 2. Increases code reusability 3. Focuses on project requirements
In BDD tests, you parameterize test steps, not scenarios or features. That is, you set parameters for the Given, When, and Then elements and their “extenders” – the And and But lines.
The following steps explain how to create test steps using BDD Gherkin scripts. Open a test case, and click the Test Script tab. Select BDD - Gherkin from the Type dropdown. The Gherkin editor appears. Write your test case. Remember not to include Feature or Scenario. Click the image to enlarge it.
We can find the following example in specs2 to implement Given When Then specs : https://github.com/etorreborre/specs2/blob/1.6/src/test/scala/org/specs2/examples/GivenWhenThenSpec.scala
Hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With