Skip to main content
1 of 2
Post Made Community Wiki
Matt Ellen
  • 3.4k
  • 4
  • 34
  • 38

I have never thought that more than one assert was a bad thing.

I do it all the time:

public void ToPredicateTest() { ResultField rf = new ResultField(ResultFieldType.Measurement, "name", 100); Predicate<ResultField> p = (new ConditionBuilder()).LessThanConst(400) .Or() .OpenParenthesis() .GreaterThanConst(500) .And() .LessThanConst(1000) .And().Not() .EqualsConst(666) .CloseParenthesis() .ToPredicate(); Assert.IsTrue(p(ResultField.FillResult(rf, 399))); Assert.IsTrue(p(ResultField.FillResult(rf, 567))); Assert.IsFalse(p(ResultField.FillResult(rf, 400))); Assert.IsFalse(p(ResultField.FillResult(rf, 666))); Assert.IsFalse(p(ResultField.FillResult(rf, 1001))); Predicate<ResultField> p2 = (new ConditionBuilder()).EqualsConst(true).ToPredicate(); Assert.IsTrue(p2(new ResultField(ResultFieldType.Confirmation, "Is True", true))); Assert.IsFalse(p2(new ResultField(ResultFieldType.Confirmation, "Is False", false))); } 

Here I use multiple asserts to make sure complex conditions can be turned into the expected predicate.

I am only testing one unit (the ToPredicate method), but I am covering everything I can think of in the test.

Matt Ellen
  • 3.4k
  • 4
  • 34
  • 38