Does isolation frameworks (Moq, RhinoMock, etc) lead to test overspecification?

Posted by Marius on Stack Overflow See other posts from Stack Overflow or by Marius
Published on 2010-05-10T07:54:40Z Indexed on 2010/05/10 8:14 UTC
Read the original article Hit count: 239

Filed under:
|

In Osherove's great book "The Art of Unit Testing" one of the test anti-patterns is over-specification which is basically the same as testing the internal state of the object instead of some expected output. To my experience, using Isolation frameworks can cause the same unwanted side effects as testing internal behavior because one tends to only implement the behavior necessary to make your stub interact with the object under test. Now if your implementation changes later on (but the contract remains the same), your test will suddenly break because you are expecting some data from the stub which was not implemented.

So what do you think is the best approach to counter this?

1) Implement your stubs/mocks fully, this has the negative side-effect of potentially making your test less readable and also specifying more than necessary to make your test pass.

2) Favor manual, fully implemented fakes.

3) Implement your stubs/fakes so that they make your test just pass, and then deal with the brittleness that this might introduce.

© Stack Overflow or respective owner

Related posts about TDD

Related posts about unit-testing