chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I was trying to use Mock.ExpectAndReturn and found the timesToRun argument to be misleading. Not that I'm complaining much :wink: . TypeMock is still great stuff.

I expected that if I specified timesToRun = 1, then TypeMock would verify that my Mocked function runs EXACTLY 1 time. Instead, timesToRun only verifies that my Mocked function is run AT LEAST 1 time.

Is there any way that I can test my ClassUnderTest in such a way that I can verify that my mocked function is not run AT ALL? That is, if my mocked function runs 1 or more times, the test would fail? I need to test that under certain conditions, my mocked function is not called.

My feeling is that this may not be possible to test. Still, if somebody has any ideas...???

Thanks very much.
asked by jimmyseow123 (4.6k points)

3 Answers

0 votes
I expected that if I specified timesToRun = 1, then TypeMock would verify that my Mocked function runs EXACTLY 1 time. Instead, timesToRun only verifies that my Mocked function is run AT LEAST 1 time.


Hi Jimmy,
This is true, the normal mode of TypeMock is to mock all expectation but to let the real code run at all other times. There is a Strict mode in which you can tell TypeMock to fail if an unexpected call is made.
The Strict mode can be set on a mock level or per method.

To set it on a mock level you can :
mock.Strict = true;


To set a certian method you can
mock.MethodSettings("Method").IsStrict = true;


See the Arbitrary Calls topic in the TypeMock User Guide.

Is there any way that I can test my ClassUnderTest in such a way that I can verify that my mocked function is not run AT ALL? That is, if my mocked function runs 1 or more times, the test would fail? I need to test that under certain conditions, my mocked function is not called.


Yes, Just set IsStrict on the method without any expecatations :-)
answered by scott (32k points)
0 votes
Wow! That's great! Sorry, still very new to all this mocking. Went through the manual quite carefully but am still trying to get the hang of it. :wink:
Thanks.
answered by jimmyseow123 (4.6k points)
0 votes
Hi,
Thats great,
:arrow: We are always striving to be better, if you can point out where you would expect information about this to be written in the documentation so that other newcomers will find it easier, or perhaps a better API, we are always glad to hear.
answered by scott (32k points)
...