JUNIT HAMCREST找不到符号资产(java.lang.Long、org.HAMCREST.Matcher<;java.lang.Long>;)

JUNIT HAMCREST找不到符号资产(java.lang.Long、org.HAMCREST.Matcher<;java.lang.Long>;),junit,compilation,hamcrest,Junit,Compilation,Hamcrest,所以我有一个简单的实体: //imports .... @Entity @Table(name="ratings") public class Rating { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; public Long getId() { return id; } public void setId(Long id) {

所以我有一个简单的实体:

//imports
....
@Entity
@Table(name="ratings")
public class Rating {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    public Long getId() {
            return id;
    }

    public void setId(Long id) {
            this.id = id;
    }

    ....
}
测试:

但是当我尝试编译时,我得到了以下编译错误:

[ERROR] /c:/limits/src/test/java/hello/RatingsControllerTest.java:[170,33] 
c:\limits\src\test\java\hello\RatingsControllerTest.java:170: cannot find symbol
symbol  : method assertThat(java.lang.Long,org.hamcrest.Matcher<java.lang.Long>)
location: class hello.RatingsControllerTest
[ERROR]/c:/limits/src/test/java/hello/ratingscocontrollertest.java:[170,33]
c:\limits\src\test\java\hello\RatingsControllerTest.java:170:找不到符号
符号:方法assertThat(java.lang.Long,org.hamcrest.Matcher)
位置:class hello.RatingsControllerTest
我检查并
is(T值)
存在,并且
assertThat(T实际,org.hamcrest.Matcher Matcher)
存在并导入。。。这是怎么回事?如果将is和assertThat组合在一起会产生编译错误,我如何测试Long是否具有我期望的值

解释我为什么要测试get id——它是一个嵌套对象,我保存在setup()中,它的getId()值在测试中显示为null,尽管我知道我保存了它(hibernate为它生成了一个id)


让我觉得自己像个白痴。

假设您使用的是最新版本的Hamcrest(1.3),该类上没有任何
assertThat
方法

您需要静态导入该类:


对我来说,我必须进口

import static org.assertj.core.api.Assertions.assertThat;

请将assertThat的静态导入添加到测试代码中。
import static org.hamcrest.MatcherAssert.*;
import static org.assertj.core.api.Assertions.assertThat;