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.

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.

Often compared

See also

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

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings