I have these values coming from a test
previousTokenValues[1] = "1378994409108"
currentTokenValues[1] = "1378994416509"
and I try
// current timestamp is greater
assertTrue(Long.parseLong(previousTokenValues[1]) > Long.parseLong(currentTokenValues[1]));
I get the java.lang.AssertionError
and detailMessage
on debugging is null
.
How can I assert greater than conditions in using JUnit
you can also try below simple soln:
Just how you've done it.
assertTrue(boolean)
also has an overloadassertTrue(String, boolean)
where theString
is the message in case of failure; you can use that if you want to print that such-and-such wasn't greater than so-and-so.You could also add
hamcrest-all
as a dependency to use matchers. See https://code.google.com/p/hamcrest/wiki/Tutorial:That gives an error like:
When using JUnit asserts, I always make the message nice and clear. It saves huge amounts of time debugging. Doing it this way avoids having to add a added dependency on hamcrest Matchers.
this passes for previous > current values
Alternatively if adding extra library such as
hamcrest
is not desirable, the logic can be implemented as utility method usingjunit
dependency only:You can put it like this