This is a migrated thread and some comments may be shown as answers.

Issue with static class interference

1 Answer 44 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 1
Lukas asked on 19 Jun 2012, 08:09 AM
Dear Telerik team,

my problem is the following: I have a static class called Context. Its data is needed in the system under test. I have two Test classes (let's say Foo and Bar). In Foo I use some methods to manually load all the stuff from the database into my Context. So I actually use it like it works in the real application. In Bar, though, I use static mocking to mock Context. Now it should look like follows:

  • If I load all the stuff from the database there is a CodeDictionary with a big amount of entries (Foo)
  • The mock is like Mock.Arrange(() => CodeDictionary[specificId]).Returns(specificValue) (Bar)

If I run them by theirselves everything works fine. But if a run both test classes at the same time they seem to interfere each other. If I debug the Bar class while running all the tests at the same time I just saw the this CodeDictionary is filled with the codes from the database. That's not the behaviour I expected. How could I get around with this? This post could not help me.

1 Answer, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 21 Jun 2012, 04:40 PM
Hi Lukas,

Thanks again for contacting us. 

In order to reproduce the issue, I would need a sample project from you to further investigate. However, it is to note that anything you setup in a class scope is shared by all test methods (Ex. Arranged something inside the constructor). Also, if code dictionary is already initialized before being mocked then it will eventually prevent JustMock from mocking.

Kind Regards
Ricky
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
Lukas
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or