An integration test verifies that several parts of a system work correctly together. Where a unit test checks one function or class in isolation, an integration test exercises real interactions, such as application code talking to a database, a message queue or another service.
Why it matters
Many bugs live at the boundaries: a wrong column name, a mismatched JSON field, a misconfigured connection or a transaction that behaves differently than expected. Unit tests with mocks cannot catch these. Integration tests give confidence that the pieces fit, at the price of being slower, harder to set up and more likely to be flaky. A common strategy is many fast unit tests, fewer integration tests and a small number of end-to-end tests, often called the test pyramid.
Example
def test_create_and_fetch_user(db): # db is a real test database
repo = UserRepo(db)
repo.create(name="Ana", email="ana@example.com")
user = repo.find_by_email("ana@example.com")
assert user.name == "Ana"
The test uses a real database, so it also validates the schema and SQL.
Common mistakes
- Sharing state between tests so they pass or fail depending on order.
- Calling live third-party services, causing flaky failures.
- Leaving test data behind instead of resetting the database.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.