【问题标题】:FakeItEasy mock interface not found找不到 FakeItEasy 模拟接口
【发布时间】:2011-04-16 20:23:52
【问题描述】:

我是 FakeItEasy 的新手,而且一般都在嘲笑。我创建了一个 Visual Studio 2010 C# 类库项目。我添加了对 NUnit DLL 和 FakeItEasy DLL 的引用。我为两者都添加了“使用”语句,然后尝试尝试一些文档示例。我的代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FakeItEasy.Core;
// ...
using NUnit.Framework;

namespace TestLib
{
    [TestFixture]
    public class Tester
    {
        [Test] 
        public void SomeTest() 
        {
            ISomething mockThing = A.Fake<ISomething>(); 
            /*
            ...
             */
        }

    }
}

我收到错误“找不到类型或命名空间名称'ISomething'”和“当前上下文中不存在名称'A'。”

我错过了什么?

【问题讨论】:

  • 好的,我解决了其中一个错误。关于“A”不存在的消息是因为我需要添加命名空间“FakeItEasy”。

标签: visual-studio-2010 mocking fakeiteasy


【解决方案1】:

事实证明,有必要创建模拟中引用的接口。它们不是自动生成的。

但是,可以指定要实现的其他接口:

var foo = A.Fake<IFoo>(x => x.Implements(typeof(IComparable)).Implements(typeof(IFormattable))); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    相关资源
    最近更新 更多