“无法验证真实对象 - 使用假对象代替”异常

我正在使用 Typemock Isolator 版本 8.6.2.0。我有以下课程:


public class A

{

    public B b { get; }


    public A()

    {

        b = new B();

    }

}


public class B

{

    public B()

    {

        Console.WriteLine("In B c'tor");

    }

    public void doSomething()

    {


    }

}

测试方法是:


public void test()

{

    Isolate.Fake.NextInstance<B>();

    A a = new A();

    var bObject = a.b;

    bObject.doSomething();

    Isolate.Verify.WasCalledWithAnyArguments(() => bObject.doSomething());

}

当我运行测试时,我得到以下异常:“无法验证真实对象 - 使用假对象代替”,但对象是伪造的!有谁知道它为什么会发生以及我如何解决它?


胡说叔叔
浏览 181回答 2
2回答

弑天下

像这样写你的测试:`&nbsp; &nbsp;public void test()&nbsp; &nbsp;{&nbsp; &nbsp; &nbsp; &nbsp;var fake = Isolate.Fake.NextInstance<B>();&nbsp; &nbsp; &nbsp; &nbsp;A a = new A();&nbsp; &nbsp; &nbsp; &nbsp;var bObject = a.b;&nbsp; &nbsp; &nbsp; &nbsp;bObject.doSomething();&nbsp; &nbsp; &nbsp; &nbsp;Isolate.Verify.WasCalledWithAnyArguments(() => fake.doSomething());&nbsp; &nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP