Integration testing is very similar to unit testing in a way that in both types of testing we test classes by making their objects invoke their methods. But they are different in how we test classes. In case of unit testing, we don't touch other objects with which our class under test is interacting with. But in integration testing, we want to see how it all works together. We let them interact with each other.
Sometimes, everything is working fine as per the unit test but not at higher-level tests (functional test or acceptance test) where we test it on the basis of requirements by hitting the URL. So, in some cases, higher-level tests are failing and unit tests are passing so to narrow down where the problem is, integration tests are very useful. So, you can consider that the integration test stands somewhere between functional tests and unit tests. Functional testing is about testing the functional requirement while unit testing is about testing a single unit. So, an integration test is in the middle of both, it tests how these single units work together; however, it tests by testing small components from code but lets them interact with each other as well.
The benefits of integration testing:
- Integration testing is useful when unit tests are not enough to catch bugs and high-level tests keep telling you that there is something wrong. So, integration tests helps in debugging the problem.
- Because of the nature of integration testing, it helps a lot in case of refactoring while telling you exactly what is affected by the new change.