Testing · English usage comparison
Unit test vs Integration test: English Usage Guide for IT Professionals
Unit tests verify a single isolated piece of code in milliseconds; integration tests verify that multiple components work correctly together, using real dependencies. Unit tests are fast and numerous; integration tests are slower but catch boundary issues that unit tests miss.
Side-by-side comparison
| Aspect | Unit test | Integration test |
|---|---|---|
| Scope | One function / class in isolation | Multiple components together |
| Dependencies | Mocked / stubbed out | Real (DB, API, file system) |
| Speed | Very fast (milliseconds) | Slower (seconds to minutes) |
| Catches | Logic bugs in isolated units | Interface mismatches, wiring errors |
Example sentences
Unit test
- "The unit test mocks the database and covers all edge cases — empty input, valid input, and the maximum length."
- "We have 800 unit tests that run in 4 seconds — they catch regressions immediately."
Integration test
- "The integration test spins up a real PostgreSQL container and verifies the full read/write cycle."
- "Our integration tests caught a serialisation mismatch that all the unit tests missed."
Exercises: choose the correct English usage
Select the best answer for each question, then check your reasoning.
1. A test calls a real database and checks the result. This is a(n) ___ test.
Explanation: Using a real database means the test verifies integration between components.
2. A test replaces the database with a mock and checks only the service logic. This is a(n) ___ test.
Explanation: Testing in isolation with mocks is the definition of a unit test.
3. Which type of test typically runs faster?
Explanation: Unit tests run in milliseconds because they use no real I/O.
4. Which sentence is correct?
Explanation: Unit tests mock dependencies and are fast. That's the defining characteristic.
5. An integration test fails but all unit tests pass. What likely happened?
Explanation: Integration failures with passing unit tests typically indicate a mismatch at the boundary between components.
Frequently asked questions
What is the "testing pyramid"?
A model that recommends many unit tests at the base (fast, cheap), fewer integration tests in the middle, and even fewer end-to-end tests at the top (slow, expensive).
What is an "end-to-end test"?
A test that simulates a real user journey through the entire system — browser to database and back. Slowest and most expensive; catches the most realistic bugs.
What is a "smoke test"?
A quick, shallow test run to check that the application starts and the most critical paths work after a deployment. Not thorough — just enough to know "it's alive".
What is a "regression test"?
A test (often automated) that verifies a previously fixed bug has not reappeared. Running the full test suite after a change is called "running regression tests".
What does "test coverage" mean?
The percentage of code lines (or branches) exercised by the test suite. High coverage doesn't guarantee quality, but very low coverage is a warning sign.
What is a "flaky test"?
A test that sometimes passes and sometimes fails without any code change — usually due to timing issues, shared state, or network dependencies.
What is TDD?
Test-Driven Development — writing the test before writing the implementation. The cycle is: red (test fails) → green (code passes) → refactor.
What is a "test double"?
An umbrella term for any object that replaces a real dependency in tests — includes mocks, stubs, fakes, spies, and dummies.
What does "arrange, act, assert" mean?
The AAA pattern for structuring tests: set up state (arrange), run the code (act), check the result (assert). Keeps tests readable.
What is "contract testing"?
Tests that verify the interface (contract) between two services — particularly useful in microservices. Tools like Pact automate this.