← All commands
✦
Development · /unit-test

Unit Test

Create focused tests for normal, boundary, and failure cases.

When to use it

Use this to plan tests for behavior across normal inputs and boundary cases.

Useful inputs

  • Unit under test
  • Expected behavior
  • Boundary cases and dependencies

Instruction

List behaviors in Given/When/Then form and provide isolated unit test examples, including boundaries and dependencies.

Example input

Method: Calculate cart total. Rule: Discount is 0–50%. Cases: Empty cart, exactly 50%, invalid discount.

Example result

- Valid cart and 0% discount → subtotal is unchanged.
- Valid cart and 50% discount → total is halved.
- Empty cart → the defined empty-cart behavior.
- 51% discount → validation error.
Fix the expected currency rounding rule in each test.

Common pitfall

Do not write tests that merely repeat current output; derive expected results from requirements.