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,

A peculiar problem. I am trying out TypeMock with MsTest. Based on advice from your support I have switched over to using C# and AAA. Good advice by the way. I really like what I can do!

After having created about 150 test methods spread out over 10+ test files I can run all tests successfully if I run them one by one.

If I run "All tests in solution" about 12 test fails. If I just continue to click the "Run selected tests" in VS the failed tests will all pass without no other action. It looks like some interference between tests?

Which test fails changes when I add new tests or based on in which order I run the tests!

There is no common set up code in the test classes. All test methods are completely self contained.

I am testing a Model-View-Controller. The controller is a live object. The model in most cases is a live object and the viewer is faked.

In the most simple tests the test method simulates a user command from the faked viewer and the controller should update the status of the model. Like this sample:

[TestMethod]
public void ShowInputWindowTest()
{
IMainViewer fakeViewer = Isolate.Fake.Instance<IMainViewer>();
MainController controller = new MainController(fakeViewer);
AssessmentContext context = controller.Context;

Framework framework = new Framework();
framework.GenerateTestContent();
Assessment assessment = new Assessment(framework);

EditSession session = new EditSession(null, assessment);
context.CurrentSession = session;

AssessmentSettings set = assessment.AssessmentSettings;
set.ShowInputWindow = false;

Isolate.NonPublic.WhenCalled(controller, "SetCurrentFormDirty").IgnoreCall();

controller.ShowInputWindow(true);

Isolate.Verify.WasCalledWithAnyArguments(() => fakeViewer.UpdateEditor(null, MainViewer.EditorUpdateMode.NewDisplayLayout));
Isolate.Verify.NonPublic.WasCalled(controller, "SetCurrentFormDirty");
Assert.AreEqual(true, set.ShowInputWindow);
}


Error message range from verification failed unexpected return value to exception null reference. Again if the test is rerun without any changes it will pass.

I do not understand what is happening and any help on how to debug further would be appreciated.

Best Regards

Mats
asked by ramnefors (3.9k points)

2 Answers

0 votes
Mats,

This may seem like a simple thing, but have you added the [Isolated] attribute to your test classes? Not doing so can cause unpredictable test results when running multiple tests.

Brian
answered by bhunter (3.4k points)
0 votes
Hi Brian,

Not consistently I am afraid :oops:

Once I added [Isolated] to the classes missing it everything worked fine. Also running under NCover 3 works OK.

Many Thanks for your help.

Mats
answered by ramnefors (3.9k points)
...