简体   繁体   English

为什么NUnit + Moq测试失败?

[英]Why does this NUnit+Moq test fail?

I hope you know, because I don't see it. 希望您知道,因为我看不到。 Bonus points for whoever figures out how one can achieve what this test is trying to achieve. 奖励积分给那些弄清楚如何才能达到此测试试图达到的目标的人。

using NUnit.Framework;
using Moq;

[TestFixture]
public class MoqHuh
{
    public class A {}
    public class B : A {}

    public interface IHelper
    {
        void DoIt(A a);
    }

    [Test]
    public void Huh()
    {
        var mock = new Mock<IHelper>();
        mock.Expect(helper => helper.DoIt(It.IsAny<B>())).Verifiable();

        mock.Object.DoIt(new B());

        mock.VerifyAll();
    }
}

Turns out this was sort of pilot error. 原来这是飞行员的错误。 I incorrectly assumed Moq working fine on Mono. 我错误地认为Moq在Mono上工作正常。 (which it looks like it does just fine). (看起来确实很好)。 This issue only happens when compiled with mono's gmcs, not when compiled with Microsofts csc. 仅当使用mono的gmcs进行编译时才会发生此问题,而使用Microsoft的csc进行编译时不会发生。

I have reported the appropriate bugs with the mono team, and will continue towards making sure the full Moq test suite passes when compiled with mono's gmcs.exe 我已经报告了Mono团队的适当错误,并将继续确保使用Mono的gmcs.exe编译时完整的Moq测试套件能够通过

Sorry for the noise. 对不起,噪音。

Lucas 卢卡斯

This test works fine. 此测试工作正常。

Since there is no system under test, you are testing that moq works as expected. 由于没有正在测试的系统,因此您正在测试moq是否按预期工作。

Sorry for not being clear enough. 抱歉,不清楚。 What I am testing is indeed that the Mock behaves as I would expect. 我正在测试的确实是该Mock的行为符合我的预期。 For me the test above fails. 对我来说,以上测试失败。 I'm very surprised to hear it passes for you. 听到它为您而过,我感到非常惊讶。 I'm running the test in VisualStudio 2008. I just upgraded to Moq 2.6, and the test still fails. 我正在Visual Studio 2008中运行测试。我刚升级到Moq 2.6,但测试仍然失败。 What version of Moq do you use with which this test passes? 该测试通过的Moq是什么版本?

从主干(3.0 beta)的最新版本无法复制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM