What is the difference between integration and unit tests?

October 26, 2018

Unit tests are designed to test a small part (often a function or method) of a system, in isolation (for example, testing a single method in a model class). Integration tests are more of a real-life test - for example, simulating a user visiting a URL and testing that it works as expected.

Unit tests are often simpler to write, and easier to debug. However, even if you know that a dozen well tested methods pass all of their tests, it does not mean that they will all work together, as they should, in the system as a whole.

Unit tests should be isolated, and should mock other components/service/modules. Integration tests should not be mocking other objects (a good exception to this is API responses should be mocked).