Search code examples
nunitassert

Is there any difference between assert.GreaterOrEqual and Assert.IsTrue in nUnit?


I am making asserts in one test and I want to test in the number of messages sent is >=1

I have two equivalent ways to do it.

        1: Assert.IsTrue(messagesSent >= 1);
        2: Assert.GreaterOrEqual(messagesSent,1);

Is there any difference between first and second way of asserting? I was wondering something inside nUnit or in the output errors or performance.. Or the only reason is readability?

If there is no difference, why the second has been created?

NOTE: Same apply for similar asserts like Greater, Less, LessOrEqual...

NOTE: I am going probably to use second one because I guess that if it has been created there is a good reason for it, but wanted to know why.


Solution

  • The output is different for failures. For IsTrue, the message will be something like "Expected true but was false." For GreaterOrEqual, the message will be something like "Expected 1 or greater, but was -15." GreaterOrEqual provides more info in that you will see the actual value, which is more useful when debugging failures.