Skip to content
Advertisement

How to assert greater than using JUnit Assert?

I have these values coming from a test

JavaScript

and I try

JavaScript

I get the java.lang.AssertionError and detailMessage on debugging is null.

How can I assert greater than conditions in using JUnit

Advertisement

Answer

Just how you’ve done it. assertTrue(boolean) also has an overload assertTrue(String, boolean) where the String 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:

JavaScript

That gives an error like:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement