Write unit tests around a business rule
In this article (3 sections)
Good unit tests explain policy at its boundaries. They should fail because the rule changed, not because a network connection disappeared.
Test the threshold
The engineering foundations lab tests shipping around a ₹500-style fixture threshold without making a commercial claim.
from engineering_cases import business_rule_case
result = business_rule_case()
assert result["all_pass"] is True
assert result["negative_rejected"] is True
assert result["cases"][0]["actual"] == 50
assert result["cases"][1]["actual"] == 0Write normal, just-below, exact-boundary, just-above and invalid cases. Include each policy override, such as membership. Give tests names that state behaviour. Keep the rule pure and inject clock, rates or repositories so tests control them.
Avoid mirroring the implementation line by line. Assert externally meaningful results and stable errors. Mutation or a deliberate bug should make at least one test fail; otherwise the suite may be decorative.
The FDE for Freshers course builds from isolated rules to integration and user-acceptance tests.
Exercise
Write a discount or eligibility rule from a short policy paragraph. Derive a decision table first, implement it second and prove a boundary mutation is caught.
Continue learning
This article is part of the FDE engineering foundations sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Use type hints to document an integration boundary.
- Continue with Use fixtures to isolate test data from production data.
Reference: pytest documentation.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our FDE for Freshers programme — 6–7 months. Build your engineering foundations, then take AI from discovery to delivery.
Explore FDE for Freshers