Need to use clarity TestCase

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: expected? Is there a way to specify the type of the return value when its own type, and not an integer, string, etc.? All the examples that I find on the Internet only return strings or ints. Should I really generate an instance of type "mytype" and say that this is what I expect?

This is NUnit 2.5.9.

+3
source share
2 answers

Test system result = ... checks the value of the result, not the type of result.

The errormessage error is misleading, since type.ToString () and object.ToString () also lead to messge

Override the myTpe.ToString () method and the error will be

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

, , . ?

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

, , , : : , , true .

0

Source: https://habr.com/ru/post/1780805/


All Articles