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

Mocking Non-public Members and Types just passes sometimes

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 1
Lukas asked on 30 May 2012, 10:01 AM
I have a couple of calls like this in my class to be testet, here a snippet:
public void AddKeys(bool resultIsValid)
{
    if (!resultIsValid)
    {
       LogMyException(message);
    }
}

I'm absolutely sure that my code works. I think the problem might be that I call a method on a static member in the LogMyException method. Anyhow, when I run the tests one by one, it works everytime. If I run them all at once they sometimes pass, but sometimes they don't. The LogMyException method is a private method and I test if LogMyException gets called as follows:

public void Test()
{
    var called = false;
 
    // Initialize test class

    Mock.NonPublic.Arrange(confStringManager, "LogMyException"ArgExpr.IsAny<string>()).DoInstead(() => called = true);

    // Do something which makes the class call LogMyException
    Assert.True(called); }




1 Answer, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 01 Jun 2012, 09:12 PM
Hi Lukas,

Thanks again for contacting us.

However, it could be that LogMyException is called in some other test method(s) that is preventing JM to intercept it in later tests.

I would recommend you to take a look into the following post that should solve your problem:
http://www.telerik.com/community/forums/justmock/general-discussions/mocks-failing-to-work-correctly-in-large-test-runs.aspx

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