CAPSTONE: THE GREEN SUITE

Three bugs, a green build and a 25-minute wait

L322 MINTESTING
PREDICT

A checkout suite is green. It tests the discount at 5000 and 20000, mocks the payment provider by hand, and uses sleep(2000) before reading stock, with CI retrying failures three times. Which statement is the safest?

This lesson combines four earlier ones. An off-by-one at a rule’s edge hides from tests that only use middle values, as boundary values showed. A mock that answers with the old response shape passes while production breaks, the trap in the mock that lied. A sleep is a guess about a race, as in the flaky test from a race (the cousin of the data race itself). And a retry that discards the first failure erases the evidence, per retries hide the bug. The honest suite fixes each at its source, and then spends the time it saved with test selection.

▶ SIMULATION
WHAT THE TEAM SEES
build: not run
time: 25 min
attempts on the sleep test: -
retries: auto x3, failures discarded
WHAT IS TRUE
discount off by one at 10000: in the code
payment mock drifted from the real response: in the code
order write races the inventory read: in the code
bugs shipping under a green build: -
last-
✓ the build is red exactly when the code is wrong✓ every bug in the code is named by a failing test✓ no failed attempt is thrown away
SCHEDULE
01[CI]CI runs the suite
02[CI]report
Start of the green suite scenario. 2 steps.
// the suite the team trusts
test('discount', () => expect(discount(5000)).toBe(0));   // middle values only
test('pays', () => expect(parse({ status: 'succeeded' }).paid).toBe(true)); // hand-written mock
test('stock', async () => { place(order); await sleep(2000); expect(stock()).toBe(9); });
// CI: retry failed tests x3, keep the last result

Open ONE CHANGE AT A TIME and watch the strip. The first run is green with three bugs in the code, and the verdict line goes red. Each change then names one more bug, and the race is the last to be named. After the fix, the last run is green and means something.

BREAK IT NOT YET

This suite is honest: it names all three bugs. Inject one change, before the CI run, that quietly stops it naming one of them. Then try the change that looks risky but is not.

GOAL: a bug in the code is not named by any failing test

FIX IT NOT YET

Write checkoutSuite(app, seed). Return an array of failure messages; an empty array means green. Spec: app.discount(subtotal) gives 10% off from 10000 inclusive (so 0 below, 1000 at 10000). app.parsePayment(resp) returns { paid } and must read what the provider really sends: app.providerReal() is the provider sandbox response, app.providerMock() is the team’s hand-written mock. app.placeOrder(steps) runs the order write and the inventory read in the order you give, ['write','read'] or ['read','write'], and returns { ok }; app.placeOrderLive() uses real timing, so it flakes on the buggy service. Orders use stock, and tests leave stock behind: call app.reset(n) to set it. The build must be red for each bug on every seed, green on the correct service on every seed, and no retry may turn a real failure green.

Mental model:

A green build is a claim, and each test is a witness that can only testify to what it could have failed on. Before you trust green, ask of every test: with the bug present, would this go red, on every run, in any order? Put tests on the edges, check mocks against the real provider, control the order of a race instead of waiting for it, and never let a retry throw away a failure.

IN PRODUCTION

Any checkout, billing or booking service with a long CI: a 20-minute suite with auto-retry, mocks of payment providers (Stripe, Paystack, Flutterwave), discount, fee and tax rules with thresholds, and stock or balance reads after a write. The review comment is: this test is green, show me the change that makes it red.

IN INTERVIEWS

“Your suite is green, slow and flaky. What do you do?” Do not start with parallelism. Say you would check what each test can fail on: add edge-value tests, verify mocks against the provider with a contract, replace sleeps with controlled schedules, record every retry attempt, and only then make it fast with test selection and a full run on merge. Close with how you would measure it: seed bugs on purpose and see which ones go red.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.