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
Unable to mock the ref and out parameter of the function, test case fails occasionally.

Sample code:

Test case:

public void test1()
{
string expected = null;
string s1 ="hi";
string s2="hello";
string xpected = "pound";

string key = "Test";
langType ret_lang = langType.English;
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
string Lang = privateTarget.CLanguage(ref key, ref ret_lang);
recorder.Return("pound").RepeatAlways();
}

privateTarget.CLa(key, ref s1, ref s2);

Assert.AreEqual(expected, s1, "s1_CLa_expected was not set correctly.");
Assert.AreEqual(xpected, s2, "s2_CLa_expected was not set correctly.");

}

Public void CLa(key, ref s1, ref s2)
{
s1 = null
s2= null
...
..........
string key = "Mother Tongue"
langType ret_lang = langType.French;

string st = CLanguage(key, ref ret_lang);

....
...

If ret_lang = French Then

s1 = st
Else
s2 = st

Endif
.....

}

When the test case fails the ret_Lang = French. Thus mocking the ref and out parameter fails occassionally.

I have tried the dynamic mocking but still the test case fails ocassionally.


I am not able to make the test case pass consistently.

Typemock.NET version 4.1.0.0

The Testcase is in C#.Net and the
Function is in VB.Net

Please help me out to resolve this issue.

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

5 Answers

0 votes
Hi Vani,

This sort of intermittent failures can point to expectations not being cleared between tests. Try decorating your tests with the [ClearMocks] attribute. Please let me know if this helps.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Hi Doron,

Thanks for the response.

I tried [ClearMocks] but still it is not working :(

Please suggest me a solution to resolve this issue ASAP.

Thanks in advance
answered by vani183 (1.7k points)
0 votes
Hi Vani,

You are using a very old version of Typemock Isolator. Upgrading to a newer version should solve the issues you've found.


Regards,

Dror
answered by dhelper (11.9k points)
0 votes
I am getting the following error when I run the test after installing Typemock Isolator 5.3.0

Initialization method DTest.DDTest.MyTestInitialize threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly 'TypeMock, Version=4.1.0.0, Culture=neutral, PublicKeyToken=3dae460033b8d8e2' or one of its dependencies. The system cannot find the file specified.=== Pre-bind state information ===
answered by vani183 (1.7k points)
0 votes
It seems that you still have reference to the old version of Typemock Isolator.

The solution is simple - make sure that the project reference the correct version and rebuild your solution.
answered by dhelper (11.9k points)
...