开发者

Curious problem with NUnit and Typemock

Using VS 2010, NUnit, Typemock, Entity Framework...

I am having a bit of an odd problem using NUnit/Typemock. I am relative new to the testing world so it could be a beginners mistake. This is the problem I am having.

  • Test Project is compiled.
  • Launch NUnit from within Visual Studio
  • Run tests from within NUnit client app. First run, first test always fails.
  • Rerun and test passes.

It does not matter what test is first. I can select a particular test. If it is the first one to run, it fails on first execution. It passes on rerun.

This is an example class having the problem. But the开发者_如何学Python class doesn't matter. Whatever test is run first has this problem. The exception code was just something that was there to test Typemock being loaded. It fails on the WhenCalled.

[TestClass, Isolated]
public class FirstTest
{

    [TestMethod]
    public void TestMe()
    {
        Exception e = new TypeMock.ArrangeActAssert.NestedCallException();
        Isolate.WhenCalled(() => UnitOfWorkManager.GetCurrentSession(null)).WillReturn(null);
        Assert.IsTrue(true);
    }
}

The following is the error message.


HCSO.ESL.Test.Fakes.FirstTest.TestMe: TypeMock.ArrangeActAssert.NestedCallException : * WhenCalled does not support using a property call as an argument. - To fix this pass false instead of AssemblyReader.IsDotNetFile


  • Example - this would work:
  • MyObj argument = Something.Other().GetStuff();
  • Isolate.WhenCalled(() => ObjUnderTest.MethodUnderTest(argument))...;


  • Example - this would not work:

  • Isolate.WhenCalled(() => ObjUnderTest.MethodUnderTest(Something.Other().GetStuff()))...;

(End error message)


Anyone have an idea why the first test always fails but runs fine on rerun? Something with how the assemblies are being loaded?

(Edit)Additional Details:


Versions: Typemock Isolator: 6.0.10.0 Visual Studio: 10.0.30319.1

In addition, I added simplified test code. This way you can see the code being tested. And yes, this test fails first time, passes on every run after that.

[TestClass, Isolated]
public class FirstTest
{

    public static int DummyCall(int i)
    {
        return 0;
    }

    [TestMethod]
    public void TestMe()
    {
        Exception e = new TypeMock.ArrangeActAssert.NestedCallException();
        //Isolate.WhenCalled(() => UnitOfWorkManager.GetCurrentSession(null)).WillReturn(null);
        Isolate.WhenCalled(() => FirstTest.DummyCall(-1)).WillReturn(1);
        Assert.IsTrue(true);
    }
}


I work at Typemock,

It seems very strange, as this is definitely not a nested call from the looks of it. Could you please try and email us a small solution demonstrating the problem to support@typemock.com?

What is UnitOfWorkManager? Is this a class belonging to EF, or is it your code?

Also, what version of Isolator are you using?


I resolved the issue. As I expected, it was partially a newbie mistake. Inside of NUnit there is a setting to determine how the assembly is isolated. The default option is to run the tests in the same process as NUnit. I tried changing the isolation in a seperate process per assembly and the problem goes away.

To reproduce error. * Make sure NUnit option for "Run tests directly in NUnit process" is selected. * Close NUnit (just to make sure setting is used) * Launch NUnit from within VS. * Select a test containing Isolate.WhenCalled() * Run that test first.

Thanks for the help.

[EDIT: Update] Updating this in the event someone else has this issue.

I found that in the NUnit client if I set the following options everything works great.

Under Settings: Test Loader -> Assembly Isolation -> Default Process Model -> Run test directly in the NUnit process.

Test Loader -> Assembly Isolation -> Default Domain Usage -> Use a seperate AppDomain per Assembly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜