Clarifying interaction based testing

time to read 2 min | 310 words

One of the big advantages to state based testing is the clearer error messages, like this:

Assert.AreEqual(5, collection.Count, "Expected to have 5 broken rules as a result of XYZ");

Using interaction based testing, you usually can specify much less information:

validationResult.AddBrokenRule(null);
LastCall.IgnoreArguements().Repeat.Times(5);

Is this a setup code? Is this the expected result of the test?

Who knows? Certianly not me in tree weeks (or months) times, when this test is broken and I need to figure out why.

I am thinking about adding a Message construct to Rhino Mocks, which wil allow to specify messages that clarify the intent of the developer. Something like this:

validationResult.AddBrokenRule(null);
LastCall.IgnoreArguements().Repeat.Times(5)
   .Message("Expected to get 5 broken rules");

There are some implementation issues (what happen when you get called too much, for instnace), but they should be workable. But before I try to add this, I would like some thoughts about the value of this feature.