Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BDD tool for Scala supporting reusable parameterized Gherkin clauses

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?

like image 630
Alexey Tigarev Avatar asked Nov 20 '11 11:11

Alexey Tigarev


People also ask

How do I write a gherkin test case in BDD?

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.

What are the advantages of using Gherkin language in BDD?

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

What is parameterization in BDD testing?

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.

How do I create test steps using BDD-Gherkin scripts?

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.


1 Answers

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.

like image 136
David Avatar answered Oct 26 '22 22:10

David