Q20 of 22 · Scenarios
How would you test a vending machine?
ScenariosJuniorscenariovending-machinelateral-thinkingfunctionalboundary-testing
Short answer
Short answer: Clarify payment methods, change-dispensing logic, and inventory tracking before listing cases. Then cover functional item selection, payment flows, change accuracy, negative states (out of stock, insufficient funds), and edge inputs.
Detail
Clarify first
- Does the machine accept cash only, card only, or both?
- Does it dispense change, and what denominations does it accept and return?
- Does the machine track inventory internally, or does a backend system manage stock?
- Are there any special modes — staff refill mode, maintenance mode?
Functional
- Select a valid item and insert the correct amount → item dispensed correctly
- Display shows item price, remaining balance, and selection confirmation in the right sequence
- Correct change returned when overpayment is made (multiple denomination combinations)
- Cancel button before item selection → full refund returned
- Card payment (if supported) completes transaction and receipt is issued
Negative / error handling
- Insufficient funds inserted before selecting item → item not dispensed; balance returned or request for additional payment shown
- Out-of-stock item selected → clear message on display; no charge made
- Unsupported coin or bill inserted → rejected and returned
- Power cut mid-transaction → money not lost (machine returns funds or logs transaction for reconciliation)
- Item jams and does not dispense → machine detects failure and offers refund or retry
Edge & boundary
- Exact change (no change needed) → item dispensed; zero change returned
- Insert correct amount then immediately cancel → full refund returned
- Machine completely out of all items → clear out-of-stock state on display; no items selectable
- Maximum coin capacity reached → machine refuses additional coins; displays a message
- Select the same item repeatedly until stock is zero → last item dispensed correctly; next attempt shows out-of-stock
Physical / mechanical
- Item dispenses into the retrieval tray, not gets stuck
- Display screen readable in direct sunlight (visibility)
- Buttons responsive and correctly mapped to selections
- Receipt printer (if present) functions; out-of-paper state handled
Close: logical and software path coverage (payment processing, inventory logic, state transitions) suits unit and simulation tests. Physical failure modes (jams, coin rejection, screen brightness) require manual testing with the hardware or a hardware test rig.
// WHAT INTERVIEWERS LOOK FOR
Structured thinking across functional, negative, and edge cases. The clarifying questions about payment type and change logic. The physical/mechanical layer mentioned — showing awareness that software testing and hardware testing are different.
// COMMON PITFALL
Listing 10 variations of 'insert money and select item' without thinking about the edge states: exact change, power cut, coin capacity, or item jams. Interviewers want to see systematic state-space coverage.