3

我有一个这样的测试:

[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。

4

2 回答 2

1

Testcase 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-30T06:17:45.240 回答
0

我以前从未见过像这样传入的结果。但是你不能把结果作为另一个参数传入吗?

[TestCase(12, 1)] 
public mytype GetById(int id, int result) 
{ 
   Assert.AreEqual(12, 1);
} 

它可能是在说明显而易见的,但预期的:但是是:听起来很像当你将“真”与真进行比较时得到的。

于 2010-12-29T12:42:43.417 回答