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,

Hoping someone can help shed some light on this issue:

When running a set of tests using VStest.Console as follows:
tmockrunner vstest.console MyTests.dll /Logger:trx

All the tests pass.

The logging is insufficient though, which is why I'm trying to execute the tests using MStest as follows:
tmockrunner mstest /testcontainer:MyTests.dll

I'm seeing failures in this case stating:
<Message>Test method MyTests.RandomTest threw exception:
TypeMock.TypeMockException:
*** Can not call Swap.AllInstances() more than once on a type</Message>


I definitely am not calling AllInstances more than once (in the same test anyway) on a type and that should be apparent considering it passes in the first case (VStest.Console).

Is it possible that MStest has issues with the [Isolated] attribute which could be why it is triggering the behavior?
asked by Synaptix (640 points)

2 Answers

0 votes
Hi,

[Isolated]attribute makes each test "clean" after itself there has to be a test
somewhere that uses swap.AllInstances on the same type but doesn't have
the Isolated attribute.

I suggest you decorate the test class with [Isolated] instead of using it
on each method or better yet use Isolated on the entire assembly.

In order to decorate assemblies with Isolated you should add
[assembly: Isolated()] to AssemblyInfo.cs which is the same as decorating
each test method with Isolated.
answered by alex (17k points)
0 votes
Thanks a bunch for this!
Isolating on the Assembly did the trick.
This gave me the ability to locate the actual issue:
It was the fact that I did not add the [Isolated] attribute to my test initialize (method tagged with [TestInitialize])
Adding the [Isolated] attribute to this (without isolating the namespace) produced the correct results.
I will in the future use the isolation on the namespace though, considering it is a much cleaner and easier approach.

Thanks again for all your assistance!
answered by Synaptix (640 points)
...