spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.54k stars 603 forks source link

Testing individual transitions and controlling current state of the state machine #814

Open ntherrien opened 4 years ago

ntherrien commented 4 years ago

Hi!

This is more of a question at this time.

I've been reading all the examples and noticed how every test plan starts with the state machine in its initial state, and then carry a bunch of events to move the state machine to the desired state of the test. For small state machines this is acceptable but I have a state machine that has already over 10 states. This means the further down the state diagram I get, the larger the event-setting paragraph gets just to put the state machine in the desired starting state for the test.

What i would like to be able to do is have 1 test per transition so that I can verify that the associated actions are being called. In each test, I would like to be able to set the current state of the state machine (Given statement) and then send the event (When Statement) and then verify that the state machine has transitioned to the correct state and called the appropriate actions (Then statement).

Is it possible to force the state machine in a particular state for purposes of testing? That is without relying on prior knowledge of which events need to be sent for the state machine to get into the desired state?

As a fall back I was thinking of enabling persistence and then mocking the persistence so that the test can control the current state about to be loaded by the state machine... Not sure if that's going to be easy but I thought I would ask this question before proceeding.

Any help or tips will be greatly appreciated.

jvalkeal commented 4 years ago

Didn't really think about this in a testing facilities but I'd assume that we could make it easier to restore machine in a particular state. We can already to this restore but it's not anyway integrated in testing facilities.