Possible duplicate:
Is unit testing worth the effort?
Well, I know what the purpose of unit tests in general is, but I found some things that bothered me.
1) The purpose of testing for early detection of errors. So, in some later iterations, if I make some changes to the code, automatic testing should bother me and tell me that I messed up a long-forgotten piece of my software.
But say that I have class A and say that it interacts with an instance of another class, call it class B.
When you write unit test for class A, it should mock class B. So, in some future, if you make some changes to class B, and this causes some errors, they will only reflect in class B unit test, and not in (because the test does not use real class B, but it is a layout with fixed inputs and outputs). So, I don’t see how unit test to make early notification of errors that no one knows about? I know about the possible errors in the class that I am changing, I don’t need a unit test for this, I need a test to warn me about the consequences of my changes, which makes an error in some “forgotten” class, and it’s not, t possibly with unit tests. Or am I wrong?
2) When you write ridicule and the correct expectations of calling methods, their input data and return values, you need to know how the sub-test class will be implemented. And I think this contradicts test-based development. In TDD, tests are written first, and, managed by them, one writes the code. But I cannot write the correct expectations (and tests in general) unless I write code that needs to be tested. This is contrary to TDD, right?
Both of these problems can be solved if I used real objects instead of mocks. But this is not unit testing, right? In unit test, the sub-test class must be isolated from the rest of the system, not using real classes, but mocks.
I’m sure that I’m wrong somewhere, but I can’t find where. I read and read, and I cannot find what I misunderstood.