Unit Tests vs. Integration Tests
Question
Describe differences between unit and integration tests.
Short interview answer
A unit test exercises a small unit of code under the developer’s control, usually without infrastructure. An integration test checks whether multiple components work together and can include real infrastructure boundaries.
Detailed answer
A unit test for PriceCalculator can construct the calculator with predictable inputs and assert its result without a database or HTTP service. That makes it quick and pinpointed when it fails. An integration test can instead verify that an API endpoint, its serialization, and a test database work together. Neither replaces the other: unit tests give rapid feedback about local behavior, while integration tests expose wiring and boundary problems that isolated tests deliberately do not cover. The appropriate balance depends on the risk of the feature and the cost of each test environment.