Using BDD to describe complex interactions in a state machine



  • How would you use BDD to describe complex interactions with a state machine?

    For example consider this scenario:

    1. User enters input into the system.
    2. The system transitions into state A.
    3. The user enters more input into the system.
    4. The system transitions into state B.
    5. The user enters some more input into the system.
    6. The system transitions into state C.
    7. Verify that the system is indeed in state C.

    Is this a single scenario? Do you describe steps 1 and 3 as Given, step 5 as When and step 7 as Then? What happens if steps 2 or 4 fail?



  • This is not a complex scenario, instead, it is common in many applications. Every application in a given user journey, goes through different states and at any step application can get into an undesired state and test might be failed.

    So yes, it can be represented as an acceptance test/end to end test where on failing at any step, remaining steps will be skipped and the test will be marked as failed.

    I think as a general rule of thumb you should try to minimize the number of asserts per test. However, as long as the test sufficiently narrows the problem to a specific place in the code, place it.

    For error-handling, at any point in any step, if a step fails like 'Element not found' which raises an exception from selenium, which is handled at cucumber level which further fails the test. So as an automation developer we don't have to handle it explicitly.

    As far as using given, when , then keywords are concerned , they are just syntactical sugar and under the hood they all are same as technically there is no difference. They are there to make a test more readable by nontechnical people as well.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2