# Unit testing vs integration testing

> Trace a pricing change across a calculation and its database boundary. Choose the smallest unit or integration test that reproduces the suspected failure.

Source: https://cueapril.com/compare/unit-vs-integration-testing
Updated: 2026-12-01
Index: https://cueapril.com/llms.txt

## 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.

Separate a pricing calculation from its database boundary. Choose the smallest test that can reproduce a rounding error, incorrect mapping or failed rollback.

Cue April editorial assessment. The sources identify documented capabilities. Suggested pilot checks are evaluation criteria.

## 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.

Unit tests vs. integration tests

| 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.

## Primary documentation

- [Ham Vocke on the practical test pyramid](https://martinfowler.com/articles/practical-test-pyramid.html)

By Cue April. Updated 2026-12-01.

## Related

- [Testing comparisons](https://cueapril.com/compare): Compare testing tools and methods against a release decision. Inspect the required evidence, maintenance work and checks each approach can provide.
- [Unit testing](https://cueapril.com/testing/unit-testing): Unit testing explained, with examples. Run your Jest or Vitest suites against a pinned code revision and inspect the native results and remaining gaps.
- [Risk-based testing](https://cueapril.com/guides/risk-based-testing): Build a risk-based test strategy with an impact and likelihood matrix. Use three worked examples to choose checks and document a release exception.
