3

我们的团队正在为 .Net 项目编写单元测试。我们使用“Visual Studio 2010”IDE、“NUnit”(v. 2.5.9)单元测试框架和“Microsoft Moles”类型隔离框架。

我们遇到了一个问题:我们无法调试使用 Moles 的单元测试(而不使用 Moles 的测试可以正常调试)。使用 Moles 的测试失败并显示以下错误消息:

Microsoft.Moles.Framework.Moles.MoleInvalidOperationException :Moles 要求测试在检测过程中。

有谁知道为什么调试这些测试不起作用?
提前致谢!

4

1 回答 1

0

从摩尔手册:

集会

Microsoft.Moles.NUnit.dll 您必须通过在 NUnit bin/addins文件夹中复制 Microsoft.Moles.NUnit.dll 程序集来向 NUnit 注册该加载项。

NUnit 版本

2.5.2.9222(对于其他 NUnit 版本,从源重新编译属性)

示例用法

using NUnit.Framework; 
using Microsoft.Moles.Framework.NUnit;
[TestFixture]
public class NUnitTest
{
    [Test]
    [Moled] // set up of the mole context around the test case
    public void TestWithMoles() {
        ...
    }

    // alternative not using [Moled]
    [Test]
    public void TestWithMoles() {
        using(MolesContext()) { // clears moles leaving context
            ...
        } 
    }
}

命令行

确保在调用 NUnit 控制台运行程序时使用 /domain=None 参数。

moles.runner.exe /r:nunit-console.exe /args=”/domain=None” ..
于 2011-04-24T12:48:18.143 回答