gpt4 book ai didi

.net - 如何调试使用 Microsoft Moles 框架的单元测试

转载 作者:行者123 更新时间:2023-12-02 23:06:48 25 4
gpt4 key购买 nike

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

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

Microsoft.Moles.Framework.Moles.MoleInvalidOperationException : Moles requires tests to be IN an instrumented process.

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

最佳答案

摘自《鼹鼠手册》:

组装

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” ..

关于.net - 如何调试使用 Microsoft Moles 框架的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5514086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com