Don’t mock my Integration test – a reply

It seems that the post I wrote yesterday – Unit Tests vs. Integration tests was well heard, Ayende wrote his take on my post his blog.

I’d like to begin by saying that no one claimed that a project should have only unit/integration tests. all I’ve said in the previous  post is that unit testing shouldn’t be hard when using mocking/faking framework (any mocking framework).

Oren makes two claims in the post:

  1. Integration tests can be written as "black box" tests without knowing the internals of the code under test where unit test require the programmer to know what happens inside the code.
  2. Using mocks in unit test leads to "less" readable code.

The two are good valid points but I’m not sure if it’s entirely correct.

Integration code does require me to understand what happens inside my code. For example if my code read from a database I need to setup the correct values before the test, if my code need registry access I need to set that up as well.

Most of the times when I write integration test I find I need to write a lot of setup code in order for the test to pass – either inside the test class or in my CI script in other words Integration testing requires environment and setting it up lead to a lot of code that has nothing to do with the actual test.


I do not think that there is a "better" type of tests, I do think that integration tests are not easier to write then unit tests.

  • Vagif Abilov

    I fully agree with you Dror. After I started splitting my tests into “Unit” and “Integration”, I spend much less time in writing pure unit tests that don’t use file system or database and usually are enough to expose 80-90% of logical errors. I still need to write integration tests to find and fix the rest of bugs, but they often require much better understanding of execution preconditions (and more code to fullfil these preconditions). Moreover, when coming to readability I’d say it’s unit tests that can better serve as API documentation.

  • Preston

    True. I too agree that knowledge of internals of the code, and how each unit interacts with other units, is required for effective Integration Testing.