This project is read-only.

Return bool from Then

Oct 10, 2010 at 5:47 PM

All of my Then methods end up with a single "Assert.True(condition);". I'd like to turn that into "return condition;". I see a number of advantages.

First, it would help remind me that I need an assertion. Sometimes I forget that line. By making it a return type, the compiler could help me.

Second, I wouldn't need to take a dependency upon any particular unit testing framework. It turns out that the only method I need from these frameworks is Assert.True.

Third, NBehave could do something intelligent with "not". If it finds the word "not" in a "then" phrase, then it could Assert.IsFalse. As it is now, I have to include a $not parameter.

Oct 12, 2010 at 10:27 PM

I can see why that would be helpful to you, but not everyone uses Assert.IsTrue for all their assertions.  Personally I prefer the more structured assertion methods such as Assert.AreEqual or CollectionAssert.Contains since they will usually better express my intent and produce more detailed messages when they fail.

Wrt your second point, there has been discussion in the past about using the Should framework so that we didn't require a unit testing framework for scenario testing.  Unfortunately it has never gotten any further than that.