我有一个这样的测试:
[TestCase(12, Result= typeof(mytype))]
public mytype GetById(int id)
{
yada, yada, yada.
}
in the NUnit error window, I see this:
Test.Tester.GetById(12):
Expected: <mytype>
But was: <mytype>我的问题是,这是意料之中的吗?当返回值是我自己的类型,而不是整数、字符串等时,有没有办法指定返回值的类型?我在web上找到的所有示例都只返回字符串或int。我真的需要生成一个mytype实例并声明它是我所期望的吗?
这是NUnit 2.5.9。
发布于 2010-12-30 14:17:45
测试用例Result=...检查结果值,而不是结果类型。
错误消息具有误导性,因为type.ToString()和object.ToString()产生相同的消息
覆盖您的myTpe.ToString()方法,错误消息将变为
Expected: <mytype>
But was: {your ToString() result goes here}这些测试(nunit 2.5.7)按预期工作
[TestCase(12, Result = "0")]
public String GetById(int id)
{
return "0";
}
[TestCase(12, Result = typeof(mytype))]
public System.Type GetByIdType(int id)
{
return typeof(mytype);
}发布于 2010-12-29 20:42:43
我以前从来没有见过像这样传入的结果。但是你不能直接把结果作为另一个参数来传递吗?
[TestCase(12, 1)]
public mytype GetById(int id, int result)
{
Assert.AreEqual(12, 1);
} 它可能是在陈述显而易见的,但也是意料之中的:但是:听起来非常像你将" true“和true进行比较时得到的结果。
https://stackoverflow.com/questions/4467159
复制相似问题