Mock.Assert and Running All Tests In Solution

3 posts, 0 answers
  1. Daniel Eggers PO 4900000041
    Daniel Eggers PO 4900000041 avatar
    3 posts
    Member since:
    Nov 2009

    Posted 21 Jun 2011 Link to this post

    Hi everyone.

    I'm having a weird problem with the the JustMock.Assert() method and "Running All Tests" in the solution.

    I wrote a solution having < 50 unit tests. In these tests, I'm using the Mock.Assert(), and the .OccursOnce() quite often. Now if I run all these tests at once using the "Run All Tests in Solution" Button some of these fail. But when I run the failing tests once again, they pass.
    This means, that I always have to run the unit test twice to get my solution green.

    It seems, that this problem appears, when Mocking the same objects in different test cases.

    One sample exception of such test would be: 
    Test method [methodname] threw exception: 
    Telerik.JustMock.MockAssertionException: Expected SAPtoADZipper.Zip(List`1) call on the mock should be once, but it was called 0 time(s).

    I'm using Just Mock version 2011.1.315.0, and Microsoft.VisualStudio.TestTools.UnitTesting in Visual Studio 2010 with C# in the 3.5 .net Framework.

    Does anyone have a hint for me, how to resolve this?
    Maybe there's a way to mark the tests to run in an isolated Thread or something.


  2. Ricky
    Ricky avatar
    467 posts

    Posted 23 Jun 2011 Link to this post

    Hi Rainer,

    Thanks again for sending the issue. However, can you check if SAPtoADZipper.Zip(List`1) executes the mock(setup) if you run the test method in a group. You can use the "Debug all tests" and put a break-point in the particular method to investigate.

    It could also be possible that the method is already invoked in some other test method; in that case you might like to check the following post:

    Kind Regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Daniel Eggers PO 4900000041
    Daniel Eggers PO 4900000041 avatar
    3 posts
    Member since:
    Nov 2009

    Posted 27 Jun 2011 Link to this post

    Hi Ricky.

    thank you for your tip. After adding Mock.Initialize<T>(); into the TestInitialize() method, all the tests go green in a single test run.

    Thank you.
Back to Top