How to assert greater than using JUnit Assert?

2020-02-20 05:47发布

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

标签: java junit
7条回答
虎瘦雄心在
2楼-- · 2020-02-20 06:18

You should add Hamcrest-library to your Build Path. It contains the needed Matchers.class which has the lessThan() method.

Dependency as below.

<dependency>
  <groupId>org.hamcrest</groupId>
  <artifactId>hamcrest-library</artifactId>
  <version>1.3</version>
  <scope>test</scope>
</dependency>
查看更多
登录 后发表回答