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
0 votes
Hi,

I am using TypeMock.NET version 4.1.0.0

My unit test case fails intermittantly

Code Sample for Unit Test:

Test1()
{
tlang ret_lang = tlang.p1;
string expected = "hii";

actual= privateTarget.CH(x,y,ref ret_lang);
Assert.Equal(actual,expected,"CH does not return the expected value");
Assert.Equal(tlang.p1,ret_lang,"CH does not return the expected value");
}

Test2()
{
tlang ret_lang = tlang.p;
string expected = "hello";

actual= privateTarget.CH(x,y,ref ret_lang);
Assert.Equal(actual,expected,"CH does not return the expected value");
Assert.Equal(tlang.p,ret_lang,"CH does not return the expected value");
}

Test3()
{
tlang ret_lang = tlang.p1;
string expected = "goodday";

using (RecordExpectations rec = RecorderManager.StartRecording())
{
string Lang = privateTarget.CH(x, y, ref ret_lang);
recorder.Return("good");
}
privateTarget.CC(a,b,c,d,e);
Assert.Equal(a,expected,"CC does not return the expected value");
Assert.Equal(b,"good","CC does not return the expected value");
}

.......................

Private Sub CC(a,b,c,d,e)
{
...
a = "badday"
....
b=CH(x,y, ref ret_lang)
....
If (ret_lang = tlang.p1) Then
a = "goodday"
EndIf

.....
}


In my case the Test3 fails intermittantly. i.e, ' a' is not equal to 'expected' though 'b' equal to 'good'. The reason for the failure is the value of 'a' in CC() is set based upon the 'ref ret_lang' value. I have mocked only the return value of the function CH() i.e. 'good' and only set the in/out ref parameter in the recorder. Though the mocked return value is caught in the function CC(), it doesnot get the value ref ret_lang = tlang.p1 properly. Instead gives ref ret_lang = tlang.p.
I assume that the ref ret_lang value fetched during fail scenario is from the previous Test case i.e. Test2() where the ret_lang = tlang.p.
And for the pass scenarios the ref ret_lang value fetched is from the Test3() where we mock CH().

only one workaround I found is to swap the tests Test1() and Test2().. So the order will be Test2, Test1, Test3 and it works fine without any failure.

My Unit TEst is in C#.Net and My functions are in VB.Net.
I am not sure whether its a typemock issue or the .Net memory allocation of ref parameter.

Kindly help me in resolving this issue.

Thanks in advance.
asked by vani183 (1.7k points)

1 Answer

0 votes
Hi,

It seems like you are not clearing expectations between test runs. Try decorating the tests with the [ClearMocks] attribute, or explicitly call MockManager.ClearAll() at the end of the test (or in your test tear-down).

Also, I strongly recommend upgrading to a recent version of Isolator - version 5.3 is out with a lot of features and bug fixes you should catch up on.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
...