Design Projects: Classic Systems · Test-writing task
Test the Shopping Cart
A free test-writing task from the How to Approach an Object-Oriented Design Interview skill. Read it here, then solve it in the app in Java.
- Medium
- Test-writing task
- Free
- Java
The problem
A grocery app in Denver has a Cart class (in the project, read-only) that a teammate just wrote. Before it ships,
write the tests for it in CartTest.
Your tests are graded by mutation testing: we plant small bugs in Cart - one per copy, each a mistake someone
could really make - and run your tests against every copy.
- Every test must pass on the real
Cart. - Each planted bug (a mutant) must make at least one of your tests fail. Then it's caught.
- You pass when you catch every mutant.
Run checks your tests against the real Cart and two sample mutants:
- A quantity of 0 is accepted.
- The 10% discount needs more than $100.
Submit checks them against all ten mutants. After you submit, you'll see which ones you caught, and how a test could have caught each one you missed.
Cart's rules are in its Javadoc: adding and removing items, quantities, the subtotal, and two promotions (buy 5
pay for 4, then 10% off from $100.00).
Constraints
- Write JUnit 5 tests in
cart/CartTest.java; you can add test helper classes undercart/. - Every test must pass on the real code; a mutant is caught when at least one test fails (or runs out of time) on it.
How it's graded
- You write JUnit tests for code you can read. Run checks that your tests pass on the real code and catch the sample bugs; Submit checks them against every planted bug.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
More problems in How to Approach an Object-Oriented Design Interview
Solve it Test the Shopping Cart free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime