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 am using VS2005 with a C# test project and TypeMock version 3.1.2.0. Using a [TestInitialize] function, each test in the test project creates some dynamic mock objects that for the units under test to interact with. One of the objects is only mocked on the first test. For each test thereafter, a method called on the object attempts to execute the real code which throws an exception because its dependents are not present.

Moving to the disassembly window, I discover code apparently placed there by TypeMock. During the first test, this code prevents the body of the function from executing. On the second test, it decides to execute the real function instead. The code snippet making this decision is presented here:
00000012 push dword ptr ds:[02330044h]
00000018 push 0
0000001a mov edx,dword ptr ds:[0232FF20h]
00000020 mov ecx,esi
00000022 call FCD233B0
00000027 mov edi,eax
00000029 test edi,edi
0000002b je 00000069

The jump instruction throws it to the real implementation. The only way I have found to get correct behavior is to move the creation of the mocks to the [ClassInitialize] method, i.e. executing only once for the entire test suite. This forces me to move the Init and Verify calls to [ClassInitialize] and [ClassCleanup] respectively. This makes the suite much more difficult to debug although I get correct behavior. Is this expected? Please advise.
asked by stimsonr (2.1k points)

1 Answer

0 votes
10 points for the depth of your debugging :-)

Unless you are using the Enterprise Edition that allows to keep expectations even after Verify(), you have to recreate all your mock object after a Verify().
What you are suggesting is actually not a very good pattern as it will make your test code hard to maintain.

To further understand what instances are getting mocked use the TypeMock Tracer. That will give you a complete understanding of how your mocks are acting.
In any case you can post a small example and that we will be willing to show you the best way to solve this.
answered by scott (32k points)
...