使用 VS 2010、NUnit、Typemock、 Entity Framework ...
我在使用 NUnit/Typemock 时遇到了一些奇怪的问题。我对测试世界还比较陌生,所以这可能是初学者的错误。这是我遇到的问题。
- 测试项目已编译。
- 从 Visual Studio 中启动 NUnit
- 在 NUnit 客户端应用程序中运行测试。第一次运行,第一次测试总是失败。
- 重新运行并测试通过。
首先进行什么测试并不重要。我可以选择一个特定的测试。如果它是第一个运行的,它将在第一次执行时失败。它在重新运行时通过。
这是一个有问题的示例类。但是类(Class)并不重要。无论先运行什么测试都会有这个问题。异常代码只是用来测试正在加载的 Typemock 的东西。它在 WhenCalled 上失败。
[TestClass, Isolated]
public class FirstTest
{
[TestMethod]
public void TestMe()
{
Exception e = new TypeMock.ArrangeActAssert.NestedCallException();
Isolate.WhenCalled(() => UnitOfWorkManager.GetCurrentSession(null)).WillReturn(null);
Assert.IsTrue(true);
}
}
错误信息如下。
HCSO.ESL.Test.Fakes.FirstTest.TestMe: TypeMock.ArrangeActAssert.NestedCallException : * WhenCalled 不支持使用属性调用作为参数。 - 修复此传递 false 而不是 AssemblyReader.IsDotNetFile
- 示例 - 这可行:
- MyObj 参数 = Something.Other().GetStuff();
Isolate.WhenCalled(() => ObjUnderTest.MethodUnderTest(argument))...;
示例 - 这是行不通的:
- Isolate.WhenCalled(() => ObjUnderTest.MethodUnderTest(Something.Other().GetStuff()))...;
(结束错误信息)
有人知道为什么第一个测试总是失败但在重新运行时运行良好吗?与如何加载程序集有关?
(编辑)其他详细信息:
版本: Typemock 隔离器:6.0.10.0 Visual Studio :10.0.30319.1
此外,我添加了简化的测试代码。这样你就可以看到被测试的代码。是的,这个测试第一次失败,之后每次运行都通过。
[TestClass, Isolated]
public class FirstTest
{
public static int DummyCall(int i)
{
return 0;
}
[TestMethod]
public void TestMe()
{
Exception e = new TypeMock.ArrangeActAssert.NestedCallException();
//Isolate.WhenCalled(() => UnitOfWorkManager.GetCurrentSession(null)).WillReturn(null);
Isolate.WhenCalled(() => FirstTest.DummyCall(-1)).WillReturn(1);
Assert.IsTrue(true);
}
}
最佳答案
我在 Typemock 工作,
看起来很奇怪,从外观上看这绝对不是嵌套调用。 您能否尝试通过电子邮件向我们发送一个演示问题的小解决方案到 support@typemock.com?
什么是UnitOfWorkManager
?这是属于 EF 的类,还是您的代码?
另外,您使用的是哪个版本的 Isolator?
关于c# - NUnit 和 Typemock 的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6781635/