Unit test vs integration test?
Options
- They are the same thing under two different names
- Unit: one piece alone. Integration: parts together (Correct option)
- Integration tests are always done manually by hand
- Unit tests always need a running server to work
Answer
A unit test checks one small piece (a function or class) in isolation; an integration test checks several parts working together, e.g. code + real database
Why
Unit test: tiny and fast (milliseconds). Tests one function with its dependencies replaced by fakes. When it fails, you know exactly where.
Integration test: checks that real parts fit together: your repository with a real PostgreSQL, or your API with its middleware. Slower but catches problems unit tests can't.
End-to-end tests go further and test the whole system like a user.
Remember
Unit = one piece alone. Integration = pieces together.