Problem: State Transition Testing Exercises
A website shopping basket starts out as empty. As purchases are selected, they are added to the shopping basket. Items can also be removed from the shopping basket. When the customer decides to check out, a summary of the items in the basket and the total cost are shown, for the customer to say whether this is OK or not. If the contents and price are OK, then you leave the summary display and go to the payment system. Otherwise you go back to shopping (so you can remove items if you want).
- Produce a state diagram showing the different states and transitions. Define a test, in terms of the sequence of states, to cover all transitions.
- Produce a state table. Give an example test for an invalid transition.
Solution
- S1: When Cart is empty
- S2: When Item added to cart, No state change when additional item added. Item can be removed which will not change state unless last item is removed. When last item is removed it will go back to S1.
- S3: When we want to checkout. If everything not ok S2 otherwise S4.
- S4: When everything ok and approved.
There are 4 states and 7 transitions.
Shopping Cart Test Cases
State | Action / Events |
---|---|
S1 | Add Item |
S2 | Remove last Item |
S1 | Add Item |
S2 | Add Item |
S2 | Remove Item |
S2 | Checkout |
S3 | Not Ok |
S2 | Checkout |
S3 | Ok |
S4 |
State Transition Table
State or Even | Add Item | Remove Item | Remove Last Item | Checkout | Not Ok | Ok |
---|---|---|---|---|---|---|
S1 Empty | S2 | - | - | - | - | - |
S2 Shopping | S2 | S2 | S1 | S3 | - | - |
S3 Summary | - | - | - | - | S2 | S4 |
S4 Payment | - | - | - | - | - | - |
Tags