Skip to main content

Integration Test

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/integration-test

In short

An integration test is an automated test that checks whether several parts of a system, such as code, a database, and an API, work correctly together.

What is an integration test?

An integration test verifies that two or more components of a system cooperate correctly. Instead of testing one function in isolation, it connects real pieces, such as your application code and a database, or two services that talk over HTTP, and checks the combined result.

A typical integration test starts real dependencies, often a test database running in a container, then sends a request or calls a service and checks both the response and any side effects, like a new row in a table. Because these tests use real infrastructure, they are slower than unit tests. They also need careful setup and cleanup so that one test's data doesn't affect another.

Think of building a car: unit tests check that the engine and the gearbox each work, while an integration test checks that the engine actually turns the wheels once everything is bolted together. Integration tests catch problems that live at the boundaries between components, such as wrong SQL queries, mismatched data formats, misconfigured middleware, or broken API contracts.

Integration tests sit between unit tests and end-to-end tests. Unlike an end-to-end test, an integration test usually doesn't drive the full application through its user interface. It focuses on a few components and the connections between them.

At a glance

A unit test calls one piece of code on its own, with a fake database; an integration test sends a real request through the API route, the code behind it and a real database running in a container, and checks that they work together.calls directlyUnit testcreateOrder()your codeFake databasein memoryIntegration testAPI routePOST /orderscreateOrder()your codePostgreSQLreal, in Dockerrun together, as in production
Integration tests are slower than unit tests but catch what those cannot: a wrong query, a missing column, a broken route.

Key takeaways

  • Integration tests check that multiple real components work together.
  • They catch bugs at boundaries, such as database queries, API contracts, and configuration.
  • They are slower than unit tests because they use real dependencies.
  • Each test should set up and clean up its own data to stay independent.

Example

Testing code against a real in-memory databasepython
import sqlite3

def save_user(db, name):
    db.execute("INSERT INTO users (name) VALUES (?)", (name,))

def find_user(db, name):
    return db.execute("SELECT name FROM users WHERE name = ?", (name,)).fetchone()

def test_save_and_find_user():
    db = sqlite3.connect(":memory:")  # a real database, kept in memory
    db.execute("CREATE TABLE users (name TEXT)")
    save_user(db, "Ada")
    assert find_user(db, "Ada") == ("Ada",)

Readers ask

What is the difference between integration testing and end-to-end testing?

Integration testing checks that a few components work together, such as a service and its database. End-to-end testing checks a complete user journey through the whole application, usually through the user interface, the way a real user would.

Should integration tests use a real database?

Usually yes, because the point is to test the real connection. Many teams start a disposable database in a container for each test run so results are realistic and data is reset between tests.

Free · once a week

Software and AI, explained once a week

The week's software and AI news with every term explained, plus a term to learn and a quick quiz. A two-minute read.

You confirm by email first, and one click unsubscribes. Privacy

See this week's issue

About this page

Page history

  1. Added a diagram: a unit test next to an integration test.

Changes that altered what this page says. Typo fixes are not listed.

Spotted a mistake or something missing on this page?Suggest an edit

How pages are made

More

Settings