Is it useful to unit test methods where the only logic is guards?

Posted by Vaccano on Programmers See other posts from Programmers or by Vaccano
Published on 2012-11-28T17:05:50Z Indexed on 2012/11/28 17:17 UTC
Read the original article Hit count: 328

Filed under:
|

Say I have a method like this:

public void OrderNewWidget(Widget widget)
{
   if ((widget.PartNumber > 0) && (widget.PartAvailable))
   {
        WigdetOrderingService.OrderNewWidgetAsync(widget.PartNumber);
   }
}

I have several such methods in my code (the front half to an async Web Service call).

I am debating if it is useful to get them covered with unit tests. Yes there is logic here, but it is only guard logic. (Meaning I make sure I have the stuff I need before I allow the web service call to happen.)

Part of me says "sure you can unit test them, but it is not worth the time" (I am on a project that is already behind schedule).

But the other side of me says, if you don't unit test them, and someone changes the Guards, then there could be problems.

But the first part of me says back, if someone changes the guards, then you are just making more work for them (because now they have to change the guards and the unit tests for the guards).

For example, if my service assumes responsibility to check for Widget availability then I may not want that guard any more. If it is under unit test, I have to change two places now.

I see pros and cons in both ways. So I thought I would ask what others have done.

© Programmers or respective owner

Related posts about c#

Related posts about unit-testing