Which failures require a real dependency to reproduce?
Use unit tests for deterministic behaviour inside one unit, such as computing a discount from a price and quantity. Use integration tests when two pieces must agree about storage, encoding, transactions or another boundary. Put each rule at the lowest level that can actually reveal its failure.
A correct amount can be stored incorrectly
Imagine a pricing function returns 1,099 cents for a line item. A focused unit check can exercise rounding, zero quantity and discount thresholds without a database. It cannot establish what a deployed database column stores. An integration check can write the amount through the real repository, open a fresh connection and read it back.
| Suspected failure | Smallest useful check | Reason |
|---|---|---|
| Percentage rounds one cent too low | Unit test with explicit expected cents | No external collaborator is needed for arithmetic. |
| Repository swaps currency and amount | Integration test through the real mapping | The error arises where objects cross into storage. |
| Partial write survives a failed update | Integration test with a real transaction | Rollback behaviour belongs to the storage boundary. |
| Discount changes at quantity ten | Unit cases for nine, ten and eleven | The cases identify the disputed business rule. |
Keep the database case diagnosable
Build a disposable database with migrations used by the release, insert one uniquely identified order and make assertions on the persisted value and currency. If the write fails, attach the migration version and actual stored representation. Keep the many arithmetic boundary examples in the unit suite so a persistence failure points to a small boundary.