Skip to main content

StateMachineTest

Trait StateMachineTest 

Source
pub trait StateMachineTest {
    type SystemUnderTest;
    type Reference: ReferenceStateMachine;

    // Required methods
    fn init_test(
        ref_state: &<Self::Reference as ReferenceStateMachine>::State,
    ) -> Self::SystemUnderTest;
    fn apply(
        state: Self::SystemUnderTest,
        ref_state: &<Self::Reference as ReferenceStateMachine>::State,
        transition: <Self::Reference as ReferenceStateMachine>::Transition,
    ) -> Self::SystemUnderTest;

    // Provided methods
    fn check_invariants(
        state: &Self::SystemUnderTest,
        ref_state: &<Self::Reference as ReferenceStateMachine>::State,
    ) { ... }
    fn teardown(
        state: Self::SystemUnderTest,
        ref_state: <Self::Reference as ReferenceStateMachine>::State,
    ) { ... }
    fn test_sequential(
        config: Config,
        ref_state: <Self::Reference as ReferenceStateMachine>::State,
        transitions: Vec<<Self::Reference as ReferenceStateMachine>::Transition>,
        seen_counter: Option<Arc<AtomicUsize>>,
    ) { ... }
}
Expand description

State machine test that relies on a reference state machine model

Required Associated Types§

Source

type SystemUnderTest

The concrete state, that is the system under test (SUT).

Source

type Reference: ReferenceStateMachine

The abstract state machine that implements ReferenceStateMachine drives the generation of the state machine’s transitions.

Required Methods§

Source

fn init_test( ref_state: &<Self::Reference as ReferenceStateMachine>::State, ) -> Self::SystemUnderTest

Initialize the state of SUT.

If the reference state machine is generated from a non-constant strategy, ensure to use it to initialize the SUT to a corresponding state.

Source

fn apply( state: Self::SystemUnderTest, ref_state: &<Self::Reference as ReferenceStateMachine>::State, transition: <Self::Reference as ReferenceStateMachine>::Transition, ) -> Self::SystemUnderTest

Apply a transition in the SUT state and check post-conditions. The post-conditions are properties of your state machine that you want to assert.

Note that the ref_state is the state after this transition is applied. You can use it to compare it with your SUT after you apply the transition.

Provided Methods§

Source

fn check_invariants( state: &Self::SystemUnderTest, ref_state: &<Self::Reference as ReferenceStateMachine>::State, )

Check some invariant on the SUT state after every transition.

Note that just like in StateMachineTest::apply you can use the ref_state to compare it with your SUT.

Source

fn teardown( state: Self::SystemUnderTest, ref_state: <Self::Reference as ReferenceStateMachine>::State, )

Override this function to add some teardown logic on the SUT state at the end of each test case. The default implementation simply drops the state.

Source

fn test_sequential( config: Config, ref_state: <Self::Reference as ReferenceStateMachine>::State, transitions: Vec<<Self::Reference as ReferenceStateMachine>::Transition>, seen_counter: Option<Arc<AtomicUsize>>, )

Run the test sequentially. You typically don’t need to override this method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§