2010-12-17 20 views
3

我有这样一个测试: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。

回答

0

我还没有看到像前面那样传递的结果。但是,难道你不能把结果作为另一个参数传递吗?

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

而且它可能说明明显,但预计:不过是: 听起来很喜欢当你比较“真”与真正的你会得到什么。

1

Testcase Result = ...检查结果值而不检查结果类型。

的errormessage的是误导,因为type.ToString()和object.ToString()产生相同的messge

覆盖您myTpe.ToString()方法和errormessage的会成为

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

感谢。我希望能够实际返回对象(并检查类型),然后使用多个链接在一起的测试用例,每个测试用例都沿着路线执行检查并将其结果返回给调用者。 – adamx97 2011-01-04 22:24:16