Unit test vs. Integration test
Published in
1 min readJan 4, 2017
Still confused about the difference between a unit test and and integration test?
Both are important tiers of the test pyramid.
Unit tests
- Run fast! We are talking ms here
- Test your code in isolation
- Mock external dependencies
- Avoid database access, network requests, and the file system
- Be able to run in parallel
- Allow you to practice TDD (if you want)
Integration tests
- Run reasonably fast. Anywhere from a few seconds to a minute
- Test how your code interacts with the framework
- May or may not mock external dependencies
- May access a local database or filesystem or network
- May or may not run in parallel
- Should NOT be used to practice TDD
Even a few seconds is too slow to get the rapid feedback required for TDD.
Integration tests are a nice second layer of defense that should be run regularly for example on a CI server. They can catch issues that might have been missed in the unit tests and offer a more realistic test environment.