With the Cucumber tests, a feature expressed as Given
, When
and Then
is usually implemented as three separate methods. These methods often need to share values, and this it seems that mutable variables are the way to do it.
Take the following simple example:
A feature:
Given the digit 2
When it is multiplied by 3
Then the result is 6
And the Cucumber methods:
class CucumberRunner extends ScalaDsl with EN with ShouldMatchers {
var digitUnderTest: Int = -1
Given("""^the digit (\d)$""") { digit: Int =>
digitUnderTest = digit
}
When("""^it is multiplied by 3$""") {
digitUnderTest = digitUnderTest * 3
}
Then("""^the result is (\d)$""") { result: Int =>
digitUnderTest should equal (result)
}
}
Is there any way, presumably built into Scala test or Cucumber-jvm for Scala, that allows me not to express digitUnderTest
as a mutable variable?