Compare what a failure tells you

A unit test can show that an order total calculation handles a discount incorrectly. It normally does not need a real database to answer that question. Controlled inputs make a failure local and help the engineer identify the business rule without first investigating service availability or shared environment state.

An integration test can show that the calculated total is stored in the wrong column or returned with the wrong JSON field. It uses the real connection relevant to that risk. Its setup is broader, so the failure report needs enough context to distinguish mapping errors from unavailable dependencies.

Choose realistic dependencies where they matter

Use a real test database when query behavior, constraints, or transaction semantics are the target. An in-memory substitute may not reproduce those details. Keep the data small and isolated so the check remains reproducible and does not depend on records created by another test running in parallel.

A stubbed downstream service can still support an integration check of your HTTP adapter, but it does not prove compatibility with the live provider. Document this boundary and add contract or sandbox evidence where necessary. Labels should help communicate evidence rather than inflate what a passing run establishes.

Combine the layers without duplicating every case

Put the full discount input matrix in unit tests, then choose a few integration cases that challenge persistence and transport. This gives fast feedback on arithmetic while retaining evidence that the assembled pieces exchange the intended values. Repeating every rule variation through the database adds cost without necessarily exposing a new risk.

When a defect escapes, identify the cheapest layer that could have caught it. A wrong comparison may need a missing unit boundary. A driver-specific transaction issue needs integration coverage. Add the check near the cause so the next failure provides a clear explanation rather than only a distant end-to-end symptom.

Working sheet

Choose the appropriate boundary
QuestionUnit testIntegration test
Discount arithmeticExact input matrixSelected persisted example
SQL constraintCannot establish real constraintReal test database
JSON mappingLocal serializer caseHTTP response contract
Provider compatibilityStub cannot prove itContract or sandbox check
Download this worksheet (CSV)

Questions about unit testing vs. integration testing

Is an HTTP client test always a unit test?

No. Inspect what it exercises. Routing, validation, and dependency wiring often make it an integration check.

Are integration tests always slow?

No. Their cost depends on the boundary and setup. Keep dependencies and data focused.

How should I use the working sheet?

Download the CSV and replace the sample rows with evidence from your repository. Record a clear acceptance check and an owner for each item. Keep unresolved assumptions visible rather than treating the example as a completed assessment.

Sources and further reading

Examples are illustrative. They are not customer results, security guarantees, or a substitute for checking the documentation for your installed version.

Make the next change verifiable.

Getzilla is an open source workflow for changes to existing repositories. Inspect the project, define acceptance checks, and keep independent review in the loop.

See the repository workflow See current access and pricing