Testing comparisons

Unit tests vs. integration tests

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

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.

Unit tests vs. integration tests
Suspected failureSmallest useful checkReason
Percentage rounds one cent too lowUnit test with explicit expected centsNo external collaborator is needed for arithmetic.
Repository swaps currency and amountIntegration test through the real mappingThe error arises where objects cross into storage.
Partial write survives a failed updateIntegration test with a real transactionRollback behaviour belongs to the storage boundary.
Discount changes at quantity tenUnit cases for nine, ten and elevenThe 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

Your next release starts here

Keep building.
Put testing to work.

Give Cue April your next testing challenge. Let your AI quality lead coordinate the checks, so your team can focus on what comes next.

Create account

Create your account, connect a repository and review your proposed setup before approving a run.