title: Mocking for integration tests
body: <p>How does one mock the many dependencies needed for integration tests?</p>
  
  <p>I use Mockito for my 'pure' unit tests.  'Pure' in this case means testing a single class, mocking all of it's dependencies.  Beautiful.</p>
  
  <p>Now come integration tests.  Let's say in this case an integration test will test something like this:</p>
  
  <ol>
  <li>Message is put on a queue</li>
  <li>Message is 'processed'</li>
  <li>Response message is put on a response queue</li>
  </ol>
  
  <p>Let's also say that the processing that happens in step 2 is serious stuff.  It relies on lots of database interactions, on multiple external services, the file system, all kinds of things.  There are also a lot of side effects that the flow will trigger, so I cannot simply ensure that the response is correct - I need to verify the side effects.</p>
  
  <p>Each of these dependencies are wrapped by a single stateless service class, which makes them nice and mockable.</p>
  
  <p>How are folks handling this?</p>
  
  <p>I would love to use Mockito so that I could verify the side effects that the above flow will have.  However,  Mocktio's documentation (and to a large extent it's implementation) seems to fight strongly against using it in contexts other than 'pure' unit tests.  I've tried to go this route, but</p>
  
  <ul>
  <li>It's difficult to populate the stub data (as there's lots of it)</li>
  <li>It's difficult to have Spring inject those stubbed instances into my beans</li>
  <li>It's difficult to 'reset' the mocks so that I can verify a different set of interactions without clearing out the stubs.</li>
  </ul>
  
  <p><em>EDIT</em></p>
  
  <p>I know that I could handle the database issue with something like an HSQLDB instance, but there's still the issue of the external services.  For repeatability I can't rely on those services being up, being in the state that I require, etc.  The only option I see there is to mock them.</p>
  
  <p>Whatdaya do?</p>