Steps
class in io.proptastic
class Steps<S>A stateful test: the steps that can be taken on a state, in any order, and what holds after every
one, from steps(Accounts::new). Each .step has a name and a domain for each of
its arguments; .when gives the step before it a precondition; .invariant names
what holds after every step. forAll(steps).check() runs it: each try starts a new state,
takes steps drawn one after another, and checks every invariant after each.
steps(Accounts::new)
.step("deposit", people(), amounts(), (accounts, to, amount) -> accounts.deposit(to, amount))
.step("transfer", people(), people(), amounts(), (accounts, from, to, amount) -> …)
.when(accounts -> accounts.total() > 0)
.invariant("money is conserved", accounts -> accounts.total() == accounts.paidIn())
A step’s own assertions are checks of that one step: a failure names it, step 3 failed: withdraw("alice", 1). A step that calls assume(…) on its arguments, before it changes
anything, is skipped when the assumption doesn’t hold, as one whose .when doesn’t.
Parameters
<S> | the state: the system under test, and the model it’s checked against |
|---|
Methods
step
Steps<S> step(String name, Steps.Step0<S> body)A step with nothing to draw.
step
<A> Steps<S> step(String name, Argument<? super S, A> a, Steps.Step1<S, A> body)A step with one argument, drawn from a: a domain, or the Handles earlier steps
kept.
step
<A, B> Steps<S> step(String name, Argument<? super S, A> a, Argument<? super S, B> b, Steps.Step2<S, A, B> body)A step with two arguments.
step
<A, B, C> Steps<S> step(String name, Argument<? super S, A> a, Argument<? super S, B> b, Argument<? super S, C> c, Steps.Step3<S, A, B, C> body)A step with three arguments.
step
<A, B, C, D> Steps<S> step(String name, Argument<? super S, A> a, Argument<? super S, B> b, Argument<? super S, C> c, Argument<? super S, D> d, Steps.Step4<S, A, B, C, D> body)A step with four arguments.
step
<A, B, C, D, E> Steps<S> step(String name, Argument<? super S, A> a, Argument<? super S, B> b, Argument<? super S, C> c, Argument<? super S, D> d, Argument<? super S, E> e, Steps.Step5<S, A, B, C, D, E> body)A step with five arguments.
step
<A, B, C, D, E, F> Steps<S> step(String name, Argument<? super S, A> a, Argument<? super S, B> b, Argument<? super S, C> c, Argument<? super S, D> d, Argument<? super S, E> e, Argument<? super S, F> f, Steps.Step6<S, A, B, C, D, E, F> body)A step with six arguments.
when
Steps<S> when(Steps.Precondition<S> holds)The step before this is taken only when holds says the state allows it; otherwise the
run skips it, its arguments still drawn, and goes on.
invariant
Steps<S> invariant(String name, Steps.Holds<S> holds)What holds at the start and after every step, whatever ran: .invariant("money is conserved", accounts -> …). A failure names it, and the step after which it broke.