What do you think about the following assertion?
Assert.IsTrue(condition1 && condition2);
I came up with this type of assertions during a review session. As far as I see using && operator in an assertion is not a good practice. I am wondering what others think? Is it worth mentioning this is an issue during the next review sessions? Or it is just a personal preference?
When you write
Assert.IsTrue(condition1 && condition2);
Then it's not clear what caused test to fail - first or second condition. Thus you need both of them to be true
just check one after another:
Assert.IsTrue(condition1);
Assert.IsTrue(condition2);
Now let's think what's wrong with OR conditions:
Assert.IsTrue(condition1 || condition2);
This looks like random test - it will pass in different scenarios:
So, what scenario you are checking exactly? Create three different scenarios which reproduce this three situations. Each tests will contain two asserts, e.g. for last scenario:
Assert.IsFalse(condition1);
Assert.IsTrue(condition2);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments