Integration Test
- In Turkish
- Entegrasyon Testi
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
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
- Unit TestTesting & Quality, p. 35A unit test is a small, automated check that verifies one function, method, or class behaves correctly in isolation from the rest of the program.
- End-to-End TestTesting & Quality, p. 8An end-to-end test is an automated test that runs a complete user journey through the whole application, from the user interface to the database and back.
- MockingTesting & Quality, p. 16Mocking is a testing technique that replaces a real dependency, such as a database or API, with a fake you control so that code can be tested in isolation.
- DatabaseDatabases, p. 6A database is an organized collection of data stored on a computer, managed by software that lets applications save, search, and update it efficiently.
- APIBackend & APIs, p. 2An API is a set of rules that lets one piece of software request data or actions from another in a predictable, documented way.
- CI/CDDevOps & Cloud, p. 9CI/CD is a set of automated practices that build, test, and release code changes frequently, so software can be delivered to users quickly and safely.
Spotted a mistake or something missing on this page?Suggest an edit