In the Scalacheck documentation for stateful testing an ATM maschine is mentioned as a use case. For it to work, the commands need parameters, for example the PIN or the withdrawal amount. In the given example the methods in the class Counter
don't have parameters.
Now my question is how I could test a method like this in scalachecks stateful testing:
class Counter {
private var n = 0
def inc(i: Int) = n += i
...
}
The run
and nextState
methods of a command don't offer a parameter. Adding a Random.nextInt
wouldn't work, because in run
and nextState
the value would differ and the test fails:
case object Inc extends UnitCommand {
def run(sut: Sut): Unit = sut.inc(Random.nextInt)
def nextState(state: State): State = state + Random.nextInt
...
}
Is there any way to pass a parameter to the Sut
?