I am currently in a class for software testing where for our semester project, we have to perform multiple types of testing on it, such as unit testing and integration testing. For integration testing, the professor said to use mocks and mocking libraries (like EasyMock and Mockito) for our integration testing. I'm getting fairly confused though. Integration testing is testing outside classes, modules, services, etc. Why would mocks and stubs be proper to use in integration testing if you are testing a multiple classes and services?

- 39,201
- 12
- 97
- 154

- 489
- 1
- 4
- 4
-
10"Integration" and "Unit" testing are not universally agreed upon terms. It's best to ask your professor exactly how they've defined those terms. – RubberDuck Apr 18 '17 at 15:26
-
1Just a comment. Integration test is not about testing the dependencies., It's about testing the right integration of the code with the dependencies (the calls, the response and error handling, etc). – Laiv Apr 18 '17 at 21:19
2 Answers
If you have a piece of functionality that touches several external components, you might mock all but one to isolate and test a specific component. For example, suppose you have a function that calls a web service and then does something with a database based on the results. You could write three integration tests:
- a test that mocks the webservice call but involves real database connectivity.
- a test that makes a real webservice call but uses mock database connectivity.
- a test that makes a real webservice call and involves a real database connection.
If you run all three tests and 1 and 3 fail, there's a good chance that there might be a bug in your code that works with the database, since the only test that passed was the one using the mock database connectivity.
In general, integration tests don't use mocks, but I have done something like this on occasion.

- 46,105
- 7
- 126
- 176
It is not immediately clear what is meant by Integration Test but the usage of Fakes/Mocks/Test Doubles is a valid technique to create test scenarios on all levels within the pyramide of tests.[1][2][3]

- 201
- 2
- 4