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.