views:

17

answers:

1

I'm using RhinoMocks to test an Add() method on a viewModel. I've got one test called AddTest()) which tests everything inside the Add() method, including

1) an item was added the viewModel items list, 2) the item was validated 3) the itemsList pagedCollection view was moved to the correct page

the problem is that this requires about 5 AssertWasCalled methods and if one of them failed, the generic error message is displayed on the screen.

What I really want is to say AssertWasCalled(...., "Item should be valid at this point"), so I know what failed.

I know this functionality exists in nUNit. I'm surprised I can't display a custom error like this using rhinoMocks...

Or is the issue that I should be using 5 unit test methods to test this functionality? Even through I'm only testing the one "unit" (e.g. Add() method) of code??

+1  A: 

You hit the nail on the head at the end: You should be using 5 unit test methods.

Even though you're only testing one "method", that method does 5 different things and they all need to be testable in isolation. If your Add method needs to do 5 different things:

step 1
step 2
step 3
step 4
step 5

Then with 5 different unit tests, you can work on the unit tests for steps 4 and 5 before getting unit tests 1-3 working (maybe someone else is working on code for 1-3 and you're doing 4 and 5). Do you wait around for them to finish? With this approach, you can target specific functionality in your unit tests.

Remember: "unit" doesn't equate to "method".

Patrick Steele