I have a kind of general question I wrote several unit tests for a bunch of connected classes and all unit tests are succeeding.
However, after implementing my first integration tests I got some errors because I didn't take some shared behavior between the classes into account.
My question is: Am I supposed to fix my unit tests because they failed to find the bugs? Are unit tests not supposed to take the other classes into account and I just bugfix my productive code because it is sufficient that the integration test cover such things.
EDIT:
due to the responses it seems necessary to specify my problem further. I am still not sure which test is responsible for what.
Lets assume I have a class(lets call it ListClass) which contains a list of objects, an index, a getCurrentValue, and a incrementIndex function. I guess the function names speak for themselves.
The index starts with -1 and if you call getCurrentValue with -1 it returns you null
I also have a reset function which sets the start index back to -1.
Okay my tests have 100% code coverage, I created mutants which were detected by my tests, so everthing seems fine.
My second class is a handler which is responsible to set all Permutations everytime i call Handler.Next().
// listContainer1.index = -1, listContainer2.index = -1,
handler.add(listContainer1) //has 2 values
handler.add(listContainer2) //has 2 values
handler.next() // listContainer1.index = 0, listContainer2.index = 0
handler.next() // listContainer1.index = 0, listContainer2.index = 1
handler.next() // listContainer1.index = 1, listContainer2.index = 0
handler.next() // listContainer1.index = 1, listContainer2.index = 1
Again 100% code coverage, mutants were detected (I used mocking to define the behaviour of the listContainer)
Here is the Integration test which broke the code: Calling reset on a listContainer, after several handler.next() calls Because the container index was -1 the next handler.next() call resulted in an not expected state.
How can I predict such an outcome in an unit test in my handler without being depent on my ListClass? Or as I asked in my original post .. Is it sufficient if the integration test catches the error.
For me it seems both unit test classes covered their own responsibilities ...