C# Interview Question #98

What is the difference between unit testing and integration testing?

SOLID, DI, Testing & Practical C# Mid-Level Intermediate

Quick Interview Answer

Unit testing focuses on a small piece of logic and normally isolates external dependencies. It is fast and useful for verifying business rules and edge cases.

Detailed Explanation

Unit testing focuses on a small piece of logic and normally isolates external dependencies. It is fast and useful for verifying business rules and edge cases.

Integration testing verifies that multiple components work together correctly. Examples include testing an ASP.NET Core API with its middleware and routing or testing EF Core against a real or representative database.

Unit tests provide fast feedback, while integration tests provide confidence that component boundaries and infrastructure work correctly. Production systems normally benefit from both.