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,

Can Fakes be created in NUnit Setup methods? I've looked all over the documentation and forum and I can't find anywhere that says they can't be used. However I can't find one Typemock sample that uses a SetUp method.

When I use SetUp methods it appears that the faked objects are still being used in a tests defined in a class that run after the tests that use the faked objects. Yes I have the Isolated attribute on the class that uses Isolator.

I have the following situation
1. Static class w/static methods that creates a needed object.
- I want to fake the static create method to return a faked instance of the
object the static create method creates
2. Singleton that gets created w/Object created my static class/methods

Argh - that was hard to explain.

Test A uses Isolator to create fakes. Test verifies that Single.Instance is not null.

Test B ( in a different test class that does not use Isolator ). Test again verifies that Singleton.Instance is not null - I expect this test to fail.(Static method throw NotImplementedException)

Test A Passes when I run it alone.
Test B Fails when I run it alone. -> This is expected.

Test B passes when I run A,B together w/B after A.

I have a sln that recreates this problem.

Environment

VS 2008 SP1
Typemock 6.0.6.0
Vista

Thanx

John A.



[/code]
asked by Jrax (1.1k points)

2 Answers

0 votes
Hi John,

Faking statics in a test fixture that includes tests that are using the fake and tests that are not using the fake in known to cause some strange behavior. :(

Can you please send us the solution with the repro to:
support at typemock.com ?
answered by ohad (35.4k points)
0 votes
HI,

Minor clarification - There are two test fixtures. One fixture has one test that uses Isolator. The other fixture has one test that does not use Isolator.


I think I made the problem go away by:
1. Changing how Singleton is created
- from ex: private static readonly Singleton _instance = new Singleton()
- to: create when Instance is first requested.
2. Disposing of singleton in test Teardown.

Thanx

JOhn A.
answered by Jrax (1.1k points)
...