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?
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.
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.