Testing Business Rules: Boundaries and Breaking It on Purpose
Why This Matters
The business rules decide whether money and goods move without a human looking. That makes them the most important code to test, and the place where a test that passes but proves nothing does the most damage.
Test cases before code
For the price rule (no more than 5% from the catalogue price), the equivalence classes and boundaries are:
| Case | Example (daypack, catalogue 64.50) | Expected |
|---|---|---|
| Same price | 64.50 | no issue |
| Just inside | +4.9% | no issue |
| On the boundary | +5% = 67.725 | ? |
| Just outside | +5.1% | issue |
| Far outside | 71.00 (+10%) | issue |
| Below catalogue | -10% | issue (a price drop can be a typo too) |
The tests in tests/test_validate.py cover inside and outside:
Break it on purpose
Green only means the tests and the code agree. Prove the tests protect you: change the rule in intake/validate.py from
MAX_PRICE_DEVIATION = 0.05
to 0.15, a realistic mistake, and run the tests:
Two tests fail, and they tell you exactly what broke: the price check, and the pipeline test that says a price change must go to a human. Restore with git restore intake/validate.py.
The boundary is a real finding
What about exactly 5%? We tried it on the real code:
| Input | Result |
|---|---|
198.45 (typed, tent at 189.00 + 5%) | accepted |
189.00 * 1.05 (calculated) | flagged: “price 198.45 differs 5% from catalog 189.00” |
The calculated price is 198.45000000000002 in floating point, a hair above 5%. So the same price is accepted or rejected depending on how it was produced, and the message “differs 5%” looks like it should be fine. That is a question for the business (is 5% allowed?) and a code fix (round prices to cents, or use Decimal). This is exactly the kind of bug testers find at boundaries, and that AI-generated tests rarely look for.
Make it a habit
For every rule test you accept, from a colleague or an AI, ask: which change to the rule would make this test fail? If you cannot name one, the test probably checks nothing.
Exercise
- Add a test for a price 10% below the catalogue. Does it pass? Should it?
- Add a test for exactly 5% using
round(64.50 * 1.05, 2). Decide what the expected result should be, and write down your question for the business. - Break the order-number rule (
r"^PO-\d{5}$"tor"^PO-\d+$"). Which test fails? Restore it. - Ask an AI assistant to fix the 5% boundary with rounding. Check its change with your test from step 2 before you accept it.
Key Takeaways
- Rules that move money or goods deserve the most careful tests.
- Test inside, on and outside every boundary.
- Break the code on purpose and check that a test with a clear name fails.
- Floating-point boundaries are real findings: decide the rule, then fix the code.

