Skip to main content
UNIT-TESTING-BASICS5 MIN READ

Build An AAA Test For A Discount Rule

Write a readable AAA unit test for one business rule using minimal setup and one Act.

Expired coupons should not reduce a cart total. The current test goes through checkout UI and fails for unrelated selector changes. Arrange only the required state, Act once, Assert the behavior result. The common trap is proving the expired-coupon rule through a full checkout journey. That adds login, rendering, routing, and selector failure modes to a pure pricing rule. Arrange Create a cart with subtotal 100.00 and an expired coupon for 20 percent off. The setup contains the minimum state that makes the rule meaningful: a price and a coupon that should be rejected. Act Call priceCart(cart, coupon) once and…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us