JUnit assertion methods should be phrased in the positive or the negative?

Viewed 2369

Should I be writing
assertTrue("User logged in", user.isLoggedIn());
or
assertTrue("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?

7 Answers
Related