我喜欢 LINQPad 并且每天都使用它。一段时间以来,我一直试图找到一种在 LINQPad 中使用 nunit 和 TypeMock 创建和运行临时测试的方法。
所以我偶然发现了一些结果,但仍然缺少一些链接。
这是我所做的:
此时,我可以让 Nunit 和 Typemock 使用一些手动步骤(需要将 nunit 和 typemock dll 复制到执行目录,例如\AppData\Local\Temp\1\LINQPad\skbidgcw)。
但是如果我将我们的程序集(我想测试的)添加到 LINQPad 脚本中,测试将失败,因为 NUnit 无法在执行目录中找到程序集。我什至尝试将所有 DLL 复制到该文件中,但这也会由于以下原因而失败:
System.IO.FileNotFoundException : Could not load file or assembly 'LINQPad, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21353812cd2a2db5' or one of its dependencies. The system cannot find the file specified.
我的 linqpad 查询在这里:http://pastebin.com/QtPNCv25
任何帮助将不胜感激!
作为旁注,我也尝试使用 NUnitLite ,虽然它可以很好地运行 Nunit 测试,但我找不到让它与 Typemock 一起工作的方法,它会引发错误,提示“Typemock Isolator 需要与 Coverage Tool 链接才能运行”。
最佳答案
终于找到了一种使用 NUnitLite 做我想做的事情的方法。
Cor_Enable_Profiling=0×1
COR_PROFILER={B146457E-9AED-4624-B1E5-968D274416EC}
(NUnitLite 可能已经在另一个 AppDomain 中运行测试,因此通过 LINQPad 设置环境变量并没有启用分析器;如果在 NUnitLite 中有一个开关,这可能会被规避,但我还没有研究过。)
现在下面应该工作。
void Main()
{
new NUnitLite.Runner.TextUI().Execute( new[]{"-noheader"} );
}
// Define other methods and classes here
[Test, Isolated]
public void TestMock()
{
Isolate.WhenCalled( () => DateTime.Now ).WillReturn( DateTime.Today );
var dt = DateTime.Now;
Assert.AreEqual( DateTime.Today, dt );
}
现在我的生活应该轻松很多。谢谢!
关于nunit - 尝试在 LINQPad 中使用 TypeMock 运行 nunit 测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13214279/