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
Is there a routine I can in TypeMock Isolator to "cleanup" after a unit test? I'm having problems w/ some unit tests passing when run individually, but failing when run together with an exception like this:

Test method UnitTestNameHere threw exception:
TypeMock.TypeMockException:
*** Static constructor for class Log cannot be faked as it has already been called

I'm guessing that a fake call I did in a prior unit test is interfering with this unit test.
asked by sorakiu (4.2k points)

16 Answers

0 votes
I guess I should read the docs more carefully. Is this [ClearMocks] attribute the one I want?

see here: [url]http://docs.typemock.com/Isolator/##typemock.chm/html/T_TypeMock_ClearMocksAttribute.htm[/url]
answered by sorakiu (4.2k points)
0 votes
I tried the attribute both on the class and the methods and I'm still getting exceptions about the Faking.

What am I missing?

More information that may or may not be relevant.
I have 2 isolator unit test projects in this SLN & 1 regular unit test project.

when I run 1 test from the first unit test project and all from the 2nd project, I get the exception.

If I run just tests from 1 project or the other, I get no exceptions.
answered by sorakiu (4.2k points)
0 votes
Hi,

ClearMocks attribute belongs to the previous Isolator API.
If you are using Arrange Act Assert API try using the [Isolated] attribute :)

Please let me know if it helps.
answered by ohad (35.4k points)
0 votes
I'm using the isolated attribute at the class level.

i.e.

[TestClass(), Isolated]
public class ServiceTest
{

I tried adding it at the method level and I'm still getting the issue.

Any ideas?
answered by sorakiu (4.2k points)
0 votes
Hi,

Can you please post here the tests code?
Also please specify which Isolator version are you using.
answered by ohad (35.4k points)
0 votes
I don't think I can due to the NDA at my company. I'm using 6.1.2

I can probably post pseudo code, if that would be helpful.
answered by sorakiu (4.2k points)
0 votes
Hi,

Sure, lets try :)
answered by ohad (35.4k points)
0 votes
Did something happen to the forums? I remember there being more in this post. I came here to say, I tried putting the unit tests in a class and then loading that class into a unique appdomain for each unit test. It seems like it is working.

I think the issue is -- and maybe your dev team has a more elegant solution is that static constructors only get called once -- so if you fake them in 1 unit test the only way to sanitize / protect the other unit tests is to put any unit test that fake a static constructor in its own appdomain.

Is this correct?
answered by sorakiu (4.2k points)
0 votes
Yes, you're correct (on both post and the static constructor). Part of the post is not here (we've upgraded the forum the last posts where not imported but I've found them in the archive).

We're working on a solution for this case, we're discussing a more general way to deal with it. We also tracked a bug related to it which we hope to fix soon.

I'll update on this post when the new solution is provided and when the bug is fixed.

Regards,
Elisha,
Typemock Support
answered by Elisha (12k points)
0 votes
Hi,

We fixed the bug, I sent you an email with the link to download it.
Please check it out and let me know if it solves the problem.
answered by ohad (35.4k points)
...