2

I love state machines because they have systematic ways to test it but i would like to discuss some philosophies with you.

enter image description here

Referring to the upper state machine, Suppose that we always start a state BED,

What is the best way to test the transitions from HOME ?

Method #1 : Access the state variable and set it directly to HOME and then preform the test

Method #2 : Initialize the state variable to its default state and trigger WAKE event to be in HOME state and then perform the test?

What method do you use and why? And if we can start at any state, What is the best method to use?

2
  • 3
    I thought the whole point behind a state machine is that the details of how you arrive at a given state are irrelevant?
    – corsiKa
    Commented Nov 7, 2020 at 21:44
  • Theoretically yes, but I believe that in the particular implementation of a state machine this might matter. Otherwise we wouldn't need do testing.
    – Alexey R.
    Commented Nov 8, 2020 at 20:22

1 Answer 1

1

Method #1 : Access the state variable and set it directly to HOME and then preform the test

Presumably, you've already got another test checking that executing WAKE changes the state from BED to HOME. Unless your state machine keeps track of past transitions, it shouldn't matter at all how the state machine arrived in state HOME. So there's no need to repeat this step for all tests of transitions starting with state HOME.

In fact, all your tests can follow the above formula: set initial state, execute transition method, check result state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.