I have a class that I'm testing. The class has a function: apply(List<IRule> rules, List<ITarget> targets);In one test I want to ensure that each target has been passed to one rule, a la:rule1.AssertWasCalled(fnord => fnord.Test(target1));rule1.AssertWasCalled(fnord => fnord.Test(target2));rule1.AssertWasCalled(fnord => fnord.Test(target3));It seems to me that limiting myself to a single assertion statement would be quite the hobgoblin. Am I correct in this assumption, or is there some other way that I could assert that each target had, in fact, been tested?
Is adhering to one assert per test foolish consistency in this case?
unit testing;code quality
The three asserts are in essence one test. You are testing behaviour of a method on a collection, to make sure that each item has been a parameter for a specific call (i.e. that each item has been processed properly).Setting the data up three times and in three different methods is wasteful and less readable than the alternative of having several asserts. The single assert rule is more about making asserts of different types in the same methods (essentially testing different things), which doesn't really apply in this case, where you are testing for a single behaviour.