When testing a method that is of return type bool.
Should you have:
expected = true;
Assert.AreEqual(expected, actual);
or
Assert.IsTrue(actual);
I know they both produce the same outcome, but which is better practise to use?
EDIT: For example, if I do AreEqual, is it not essentially the same as doing IsTrue on a method that returns a string a la below:
string expected = “true”;
string actual = test.testMethod(data)
bool test;
if expected.equals(actual)
test = true;
else
test = false;
Assert.IsTrue(test);
You should only use Assert.IsTrue
if you're testing something which directly returns a boolean that should always be true.
You should not massage data to get a boolean for IsTrue
; instead, you should call a more relevant method in Assert
or CollectionAssert
.
In your edited example, you should by all means call Assert.AreEqual
instead; it will give you a much nicer message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With