Argument Checking

One common use of a mocking framework is to check interaction between classes, Specifically checking correct arguments passing between calls.

Like any other framework Typemock Isolator also contain such an ability:

using (RecordExpectations recorder = RecorderManager.StartRecording())
MyClass mock = new MyClass();

However when doing so its important to note that the verification is done during the actual call time. When later on in the test when someone calls the DoStuff method and passes arguments they are checked immediately and the Isolator will fail the test by throwing an exception on the call.

this approach which is used by most framework can be confusing when happening inside a try-catch block.

for example the following code will not fail as expected:

MyClass target = new MyClass();
//some error handling code

The exception thrown by the Isolator is caught, and in most cases not re-thrown and the test does not see it.

The trick to solve such an issue is to defer the argument checking to the final verification stage (the call to MockManager.Verify) by doing:

MockManager.ValidateArgsOnVerify = true;

That being said we are working on removing the need for the user to specify this. We hope to incorporate this in our next release.

  • brett

    I have a similar situation that I am unable to work around. Rather than checking arguments I just want to validate that a function doesn’t get called (I want to make sure my validation stops a save from getting called). I call recorder.FailWhenCalled but my function is swallowing exceptions so the exception doesn’t come back to me when the function is called. Based on this post I then tried calling MockManager.Verify but I’m not getting the exception then either. Is there some way around this that I’m not aware of?

  • Gil Zilberfeld

    Hi Brett,

    This is currently not supported. See my response here.