Verbosity Isn’t Always a Bad Thing
- by PSteele
There was a message posted to the Rhino.Mocks forums yesterday about verifying a single parameter of a method that accepted 5 parameters. The code looked like this:
[TestMethod]
public void ShouldCallTheAvanceServiceWithTheAValidGuid()
{
_sut.Send(_sampleInput);
_avanceInterface.AssertWasCalled(x => x.SendData(
Arg<Guid>.Is.Equal(Guid.Empty),
Arg<string>.Is.Anything,
Arg<string>.Is.Anything,
Arg<string>.Is.Anything,
Arg<string>.Is.Anything));
}
Not the prettiest code, but it does work.
I was going to reply that he could use the “GetArgumentsForCallsMadeOn” method to pull out an array that would contain all of the arguments. A quick check of “args[0]” would be all that he needed. But then Tim Barcz replied with the following:
Just to help allay your fears a bit...this verbosity isn't always a bad thing. When I read the code, based on the syntax you have used I know that for this particular test no parameters matter except the first...extremely useful in my opinion.
An excellent point! We need to make sure our unit tests are as clear as our code.
Technorati Tags: Rhino.Mocks,Unit Testing