title: Unit tests - The benefit from unit tests with contract changes?
body: <p>Recently I had an interesting discussion with a colleague about unit tests. We were discussing when maintaining unit tests became less productive, when your contracts change.</p>
  
  <p>Perhaps anyone can enlight me how to approach this problem. Let me elaborate:<br></p>
  
  <p>So lets say there is a class which does some nifty calculations. The contract says that it should calculate a number, or it returns -1 when it fails for some reason.</p>
  
  <p>I have contract tests who test that. And in all my other tests I stub this nifty calculator thingy.</p>
  
  <p>So now I change the contract, whenever it cannot calculate it will throw a CannotCalculateException. </p>
  
  <p>My contract tests will fail, and I will fix them accordingly. But, all my mocked/stubbed objects will still use the old contract rules. These tests will succeed, while they should not!</p>
  
  <p>The question that rises, is that with this faith in unit testing, how much faith can be placed in such changes... The unit tests succeed, but bugs will occur when testing the application. The tests using this calculator will need to be fixed, which costs time and may even be stubbed/mocked a lot of times...</p>
  
  <p>How do you think about this case? I never thought about it thourougly. In my opinion, these changes to unit tests would be acceptable. If I do not use unit tests, I would also see such bugs arise within test phase (by testers). Yet I am not confident enough to point out what will cost more time (or less).</p>
  
  <p>Any thoughts?</p>