{"canonical_url":"https://engineer.company/glossary/integration-test/","content_markdown":"# Integration test\n\n## What it is\n\nAn integration test exercises a boundary where several parts of a system have to\nwork together. It can call an application through its HTTP interface and check\nwhat it writes to a real database. It can run a job against a queue and assert\nthat another component consumes the result. The test gives those parts realistic\ninputs and checks behaviour that depends on their interaction.\n\nChoose the boundary by asking where the failure could occur. A review might want\nto know whether an API maps database errors to the correct client response. That\ntest needs the HTTP handler, the code that calls the database and a database\nthat returns the actual error. It can use a smaller environment for other\nservices that are outside the question. The result is easier to understand when\nthe test makes its real dependencies and its controlled substitutes explicit.\n\nIntegration tests can run within one service or across several services. What\nmatters is the contract the test proves. A repository test that uses the\ndatabase driver, migrations and real transaction handling can be an integration\ntest even though it runs no browser. A larger user journey adds evidence about\nthe visible product. Match the scope to the behaviour and keep the reason for\nthe chosen setup visible in the test.\n\n## Why it matters\n\nSome failures exist only at the seam between components. A driver may encode a\ntimestamp with a different timezone from the one the application expects. A\ndatabase can reject a concurrent update after both request handlers made it\nthrough their in-memory validation. A queue worker may see a change only after\nthe sender commits. A test that replaces that dependency with a simple in-memory\nresponse can leave those conditions unobserved.\n\nA realistic boundary also exposes configuration mistakes. A schema may be\nmissing in the database created by a fresh release, or a real client can send an\nomitted field in a different way from the application's fixture. Running the\nintegration in a repeatable environment shows both the outcome and the\nconfiguration necessary to get it. Test a new installation when the application\ncan create one, and add a representative upgrade fixture when existing data\naffects the decision.\n\nThere is a cost to that realism. It takes longer to provision a dependency and\nthe test suite needs a way to clean up state. A focused integration suite spends\nthat cost on the parts that have to agree. Keep separate tests for inexpensive\npure logic so failures can still be diagnosed quickly. A good integration result\nlets a maintainer identify the relevant request, boundary and state when a\nchange causes the test to fail.\n\n## What it looks like in practice\n\nConsider an API that reserves a limited item. Start the database with the same\nmigrations used by the application, load a small inventory with a known balance\nand call the route with a valid request. Assert the response, the reservation\nrecord and the resulting balance. Then issue the same operation against an\nexhausted item. Check the documented error result and confirm that the database\ncontains no partial reservation.\n\nGive the fixture a known starting state. An isolated schema, database or\ncontainer avoids accidental dependencies on a previous test. Control the clock\nwhere deadlines matter. Record the response, supporting database state and any\nnotices from the dependency if the assertion fails. This is more useful than an\nopaque report that an HTTP request returned the wrong number. It lets a reviewer\nsee where the disagreement started.\n\nEngineer's\n[Go, SQL and browser testing case study](/portfolio/built-a-test-suite-across-go-sql-and-browser/)\ndescribes testing stored functions where the database executes them and using\nother suites for API and browser behaviour. The hypothetical reservation test\nfollows that reasoning across a specific seam. Use real effects where the\noutcome depends on them and keep the fixture small enough that the tested\ninvariant remains obvious. A browser journey can then check the response readers\nactually see without carrying every database scenario through the interface.\n\n## Where it goes wrong\n\nTests can depend on order without saying so. A previous test might leave a\ncustomer, a schema mutation or a queued job that changes the next one's result.\nRe-run an individual failure by itself and verify the starting conditions. Use\nfixtures whose identifiers and data are deliberately scoped to the test, and\nmake cleanup reliable even after an assertion or dependency fails.\n\nA wait based on a fixed sleep can also make a healthy operation fail\nintermittently. Wait for the event that establishes readiness or completion,\nwith an explicit deadline and useful diagnostics on timeout. A database\nreadiness check might need to prove it can accept a query after migrations. A\nqueue test can wait for the completion record of the specific job it submitted.\n\nUse versions that reproduce the contract you intend to support. A fixture that\nalways starts the newest database can miss a problem with an older supported\nversion. A fixture copied from a developer's machine can hide state that a\nrelease is required to create. Name the supported dependency version or image in\nthe test record. Add an explicit scenario with the schema and data from before a\nmigration when upgrades are part of the product's normal route.\n\nFinally, make each assertion show the behaviour the integration was chosen to\nprove. A green request can coexist with database state that a later operation\ncannot read. Check the effect and the application response together where both\nmatter. Retain a representative failing path and exercise it as the integration\nchanges. The suite's value comes from being able to explain an actual agreement\nbetween parts of the system and how a reader will know when it breaks.\n\n## Further reading\n\n- [ASP.NET Core integration testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests).\n  Describes hosting an application and exercising the request path in tests.\n- [Testcontainers for Java](https://java.testcontainers.org/). Documents\n  disposable service dependencies for tests.\n- [Go HTTP testing utilities](https://pkg.go.dev/net/http/httptest). Shows\n  standard-library tools for HTTP fixtures and test servers.\n\n\u003chttps://engineer.company/glossary/integration-test/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Test an application with a real database using deterministic state and evidence from both sides of the boundary.","formats":{"gemtext":"https://engineer.company/glossary/integration-test/index.gmi","gopher":"https://engineer.company/glossary/integration-test/gophermap","html":"https://engineer.company/glossary/integration-test/","json":"https://engineer.company/glossary/integration-test/index.json","markdown":"https://engineer.company/glossary/integration-test/index.md","pdf":"https://engineer.company/glossary/integration-test/index.pdf"},"kind":"page","language":"en","title":"What is an integration test?","url":"https://engineer.company/glossary/integration-test/","version":1}