0

I would like to test this method using UnitTest, but I have no clue how to approach to this return type even the method does not make sens or anything

public Result ChangeVoucherStatus(long[] voucherIDs, GenericStatus newStatus, Context context)
{
    ... 
    return new Result(true, resMsg);
}

I am using Visual Studio 2012 and NUnit test adapter Any suggestions?

I have tested the void methods but this scared me.

5
  • 1
    Its all the same thing. You just need to capture the return from your tested item (ie your Result object) and then make sure it looks right (eg that your boolean is correct given your inputs or that your mresMsg says the same thing). If the method doesn't make sense then you might need to sort that out before worrying about testing it... Commented Sep 12, 2014 at 10:00
  • What is of type Result - is that custom type ? Commented Sep 12, 2014 at 10:00
  • in Unit test i need to catch the Object Result and get out of that 2 things boolean and message is that correct? *and method does not make sens here, here in this question Commented Sep 12, 2014 at 10:05
  • 1
    @user37202: broadly yes. The idea is that you can test internal behaviour the same as with a void method. In this case though you also need to check that your returned object is as expected. How you determine if it is as expected is for you to establish. You may be able to just compare it to a Result object that you've created manually or you may have to test key properties individually. Essentially it boils down to if you know the input you should know the output so you can test the output is what it should be. Commented Sep 12, 2014 at 10:08
  • it is just a return type in this case it is object took me a while to figure it out thanks Commented Sep 12, 2014 at 11:36

1 Answer 1

4

with xunit

You can do something like that

[Fact]
public void TestChangeVoucherStatus(){

   var vocherIDs = ...;
   var newStatus = ...;
   var context = ...;

   var result = ChangeVoucherStatus(voucherIDs, newStatus, context);

   Assert.Equal(result.resMsg, "")

}

with nunit

[TestFixture]
class Test {
    [Test]
    public void TestChangeVoucherStatus(){

       var vocherIDs = ...;
       var newStatus = ...;
       var context = ...;

       var result = ChangeVoucherStatus(voucherIDs, newStatus, context);

       Assert.Equal(result.resMsg, "")

    }
...
}
Sign up to request clarification or add additional context in comments.

1 Comment

that is with XUnit but what about NUnit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.