开发者

NUnit use of TestCase clarity needed

开发者 https://www.devze.com 2023-01-30 20:20 出处:网络
I have a test like this: [TestCase(12, Result= typeof(mytype))] public mytype GetById(int id) { yada, yada, yada.

I have a test like this:

[TestCase(12, Result= typeof(mytype))]
public mytype GetById(int id)
{
yada, yada, yada.

}

in t开发者_如何学Gohe 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.


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

 Expected: <mytype>
 But was:  {your ToString() result goes here}

these tests (nunit 2.5.7) work as expected

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


I haven't seen the result being passed in like that before. But couldn't you just pass the result in as another parameter?

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

and it's probably stating the obvious, but Expected: But was: sounds very like what you'd get when you compare "true" with true.

0

精彩评论

暂无评论...
验证码 换一张
取 消