Why should I bother with unit testing if I can just use integration tests?
- by CodeGrue
Ok, I know I am going out on a limb making a statement like that, so my question is for everyone to convince me I am wrong. Take this scenario:
I have method A, which calls method B, and they are in different layers.
So I unit test B, which delivers null as a result. So I test that null is returned, and the unit test passes. Nice.
Then I unit test A, which expects an empty string to be returned from B. So I mock the layer B is in, an empty string is return, the test passes. Nice again. (Assume I don't realize the relationship of A and B, or that maybe two differente people are building these methods)
My concern is that we don't find the real problem until we test A and B togther, i.e. Integration Testing. Since an integration test provides coverage over the unit test area, it seems like a waste of effort to build all these unit tests that really don't tell us anything (or very much) meaningful.
Why am I wrong?