How Would You Test a Vending Machine?

How Would You Test a Vending MachineHow would you test a vending machine? This is a classic example of a software testing in the wild interview question, where you are supposed to show off both your formal knowledge of testing techniques as well as your creative and technical side in inventing test cases.

So, how would you answer this question?

The absolute first thing is that you should talk about the specifications  for a vending machine. Without this, it’s impossible to test anything. You can either ask your interviewers to give you specifications for the exact kind of vending machine you should test, or you can invent some specifications on your own and present that (see the example below).

You should then explain that that there are lots of different kinds of tests that we might want to apply to a vending machine for. First of all, there’s the functionality – does the vending machine do what it’s supposed to do? Then there’s performance – can the vending machine handle lots of subsequent requests; or, how much electricity does it spend for a typical request? We might also be interested in security – is it possible to break into the vending machine easily and steal the candy or the money?

Finally, you can work your way through an example, given specifications for a vending machine, and a kind of test.

Let’s focus on testing the functionality of a typical vending machine that takes in an arbitrary amount of money, and sells several products (like the usual soda vending machines).

Here is a list of possible specifications:

  1. The vending machine will only dispense the product if enough money was put in
  2. The vending machine will return the correct change in case too much money was put in
  3. The vending machine will correctly dispense the selected product (and not something else)
  4. If the user doesn’t select anything within 30 seconds, the vending machine will return the user’s money

And here is a list of possible test cases:

  1. Select a product, put in exact change. The selected product should be dispensed.
  2. Select a different product, and do the same test as above.
  3. Select a product, put in too much money. The correct change should be returned.
  4. Select a product, put in insufficient change. The product should not be dispensed, but the change should be returned.
  5. Put in change, but don’t select a product. Wait 30 seconds. The change should be returned.
  6. Select a product, but don’t put in any money. The product should not be dispensed.
  7. Enter in an invalid product number. Nothing should happen.
  8. Put in foreign money. It should be returned and the product should not be dispensed.
  9. Put in a metal disc of the same size as a coin. It should be returned and the product should not be dispensed.
  10. Put in the correct change, then turn off the power. What happens then? Consult the specification.
There are lots of other possible tests you could come up with – vending machines get pretty complicated after all. However, the point here is not to come up with a perfect test suite for a vending machine, but to display your overall knowledge and skill with software testing. The interviewers want to see how you would handle a complex problem.
In summary, when asked how you would test a vending machine, first talk about the necessary specifications for the vending machine. Second, talk about the different kinds of testing that could be done. Finally, walk through some sample test cases to illustrate how you think about testing.