In writing unit tests, for each object that the unit interacts with, I am taking these steps (stolen from my understanding of JBrains\' Integration Tests are a Scam):
I do it this way.
Suppose I have to change the responses from interface method foo()
. I gather all the collaboration tests that stub foo()
in a list. I gather all the contract tests for method foo()
, or if I don't have contract tests, I gather all the tests for all the current implementations of foo()
in a list.
Now I create a version control branch, because it'll be messy for a while.
I @Ignore
(JUnit speak) or otherwise disable the collaboration tests that stub foo()
and start re-implementing and re-running them one by one. I get them all passing. I can do this without touching any production implementation of foo()
.
Now I re-implement the objects that implement foo()
one by one with expected results that match the new return values from the stubs. Remember: stubs in collaboration tests correspond to expected results in contract tests.
At this point, all the collaboration tests now assume the new responses from foo()
and the contract tests/implementation tests now expect the new responses from foo()
, so It Should All Just Work.(TM)
Now integrate your branch and pour yourself some wine.