21

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?

  • 6
    "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
  • Just 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
21

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:

  1. a test that mocks the webservice call but involves real database connectivity.
  2. a test that makes a real webservice call but uses mock database connectivity.
  3. 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.

5

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]

protected by gnat Jul 20 '18 at 11:55

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.