简体   繁体   English

找不到assertThat

[英]Can't find assertThat

Here is my code 这是我的代码

import org.junit.Test;

import static org.junit.Assert.assertThat;
import static sun.nio.cs.Surrogate.is;

public class PlayerTest {
  public void should_return_3_when_status_is_3(){
        Player player = new Player();
        assertThat(player.getStatus(),is(3));
    }
}

And here is the trace 这是追踪

Can't find symbol
符号: method assertThat(int,boolean)
位置: class PlayerTest

my iml file is 我的iml文件是

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="module-library" scope="TEST">
      <library>
        <CLASSES>
          <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.10.jar!/" />
        </CLASSES>
        <JAVADOC />
        <SOURCES />
      </library>
    </orderEntry>
  </component>
</module>

I think I used it before,but it not works now. 我想以前用过它,但现在不行。 Have no clue about what to do.However assertTrue is working. 不知道该怎么做。但是assertTrue正在工作。 Ubuntu 11.04 is being used. 正在使用Ubuntu 11.04。

The mistake is in 错误在于

import static sun.nio.cs.Surrogate.is;

is() should return a matcher, but whatever this is, it returns boolean. is()应该返回一个匹配器,但无论如何,它都返回boolean。 Try org.hamcrest.Matchers.is or org.hamcrest.CoreMatchers.is instead. 请尝试使用org.hamcrest.Matchers.isorg.hamcrest.CoreMatchers.is

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM