我有这样的测试:

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

最佳答案

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);
    }

07-28 03:25
查看更多