Should I be writingassertTrue("User logged in", user.isLoggedIn());
orassertTrue("User is not logged in", user.isLoggedIn());
The former provides better reading inside the source files:
"I assert that the following is true: User logged in."
The error message could be read both ways:java.lang.AssertionError: User logged in
"There is an error in asserting that the user is logged in"
"The error is that the user is logged in."
JUnit documentation doesn't provide a clear guide to which it should be, except it is
"the identifying message for the {@link AssertionError}",
And in both cases, the text identifies the test being run.
What's the common usage?
What does assertSame() method use for assertion? Explanation: == is used to compare the objects not the content. assertSame() method compares to check if actual and expected are the same objects.
An assertion method compares the actual value returned by a test to the expected value, and throws an AssertionException if the comparison test fails.
What is Junit Assert? Assert is a method useful in determining Pass or Fail status of a test case, The assert methods are provided by the class org.
How about:
assertTrue("User should be logged in", user.isLoggedIn());
Works both ways.
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