Issue with static class interference

2 posts, 1 answers
  1. Lukas
    Lukas avatar
    20 posts
    Member since:
    Jul 2011

    Posted 19 Jun 2012 Link to this post

    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.
  2. Answer
    Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 21 Jun 2012 Link to this post

    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 >>

  3. DevCraft R3 2016 release webinar banner
Back to Top