State transition Shopping Cart exercise

Profile picture for user devraj

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).

  1. Produce a state diagram showing the different states and transitions. Define a test, in terms of the sequence of states, to cover all transitions.
  2. Produce a state table. Give an example test for an invalid transition.


  • 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

StateAction / Events
S1Add Item
S2Remove last Item
S1Add Item
S2Add Item
S2Remove Item
S3Not Ok

State Transition Table

State or EvenAdd ItemRemove ItemRemove Last ItemCheckoutNot OkOk
S1 EmptyS2-----
S2 ShoppingS2S2S1S3--
S3 Summary----S2S4
S4 Payment------