NUnit 使用 TestCase 需要清晰
我有一个这样的测试:
[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>
我的问题是,这是预期的吗?有没有办法指定返回值的类型,当它是我自己的类型时,而不是整数、字符串等?我在网上找到的所有示例都只返回字符串或整数。我是否需要实际生成一个 mytype 实例并说它是我所期望的?
这是 NUnit 2.5.9。
I have a test like this:
[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>
My question is, is this expected? Is there a way to specify the type of the returned value when its my own type, and not an integer, string, etc? All the examples I find on the web are only returning strings or ints. Do I need to actually generate a mytype instance and say that it is what I'm expecting?
This is NUnit 2.5.9.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Testcase Result=... 检查结果值而不是结果类型。
错误消息具有误导性,因为 type.ToString() 和 object.ToString() 会产生相同的消息
覆盖您的 myTpe.ToString() 方法,错误消息将成为
这些测试(nunit 2.5.7)按预期工作
Testcase Result=... checks the result value and not the result type.
The errormessage is misleading because type.ToString() and the object.ToString() result in the same messge
Override your myTpe.ToString() method and the errormessage will become
these tests (nunit 2.5.7) work as expected
我以前从未见过这样传递结果。但是您不能将结果作为另一个参数传递吗?
它可能陈述了显而易见的事情,但预期:但是:
听起来很像将“true”与 true 进行比较时得到的结果。
I haven't seen the result being passed in like that before. But couldn't you just pass the result in as another parameter?
and it's probably stating the obvious, but Expected: But was:
sounds very like what you'd get when you compare "true" with true.