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 Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Unit Tests failing intermittently with TypeMock

+1 vote
I have an NUnit TestFixture with 14 tests; most (13) run fine with DotCover without failing every single time. There is one test, however that always fails when ran in the above-mentioned \\\"bulk-running\\\" procedure; but if I run it by itself it passes.

Now, if I ignore the above failing method and all the rest (13) all pass just fine.

My setup: I have setup() and teardown() methods (included to rule-out anything weird) that looks like the following; yes, I am not using the Isolated attribute in the TestFixture class:

\\\"TestUtil.ResetAllStatics();            
TypeMock.MockManager.ClearAll();\\\"

There is nothing exciting about these unit tests except faking the next instance :

 var fakeUdpTarget = Isolate.Fake.NextInstance<UdpTarget>();

Wondering if you have seen this in the past from perhaps other customers and if you can provide a work-around to getting this intermittent test to pass every single time.

I don\\\'t think I can \\\"debug\\\" this failing test but I\\\'ll give it a shot by running both and setting a breakpoint on the latter.

The theory is that setup for the first is not getting properly cleaned up when the 2nd one runs..... The failure message is on the assert which means the \\\"setup\\\" was wrong; but again, the unit test runs fine in Isolation.

I\\\'ve also read this post:

https://www.typemock.com/answers/11230/isolated-attribute-clear-mocks-before-test-ends

Thanks!

Solved my own problem:

The class under test had a static constructor which needs to be called per each test with TypeMock-> Isolate.Invoke.StaticConstructor<myclass>();
asked Apr 16 by afuste (1,120 points)

1 Answer

0 votes

Hi Alejandro,

Can I presume from your note in the end that the problem is solved?

Also, check that you have the Isolated attribute either on TestFixture level or each Test level.

And as the link you attached says, MockManager is the old API. You can add Isolate.CleanUp() to the end of every test but that what the Isolated attribute is for.

answered Apr 17 by Raphy (3,800 points)
...