java - juit 用assertThat 提示我找不到符号
PHP中文网
PHP中文网 2017-04-17 11:00:54
[Java讨论组]

代码如下,用的是intelij idea社区版。

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));
    }
}

提示错误
`找不到符号
符号: 方法 assertThat(int,boolean)
位置: 类 PlayerTest`
项目的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>
PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(1)
阿神

楼主学习一下看官方 API 手册吧。

http://junit.sourceforge.net/javadoc/org/junit/Assert.html (需翻墙)

必须是 junit4

assertThat 一般这样用:

import org.hamcrest.Matchers;

assertThat(105, Matchers.greaterThan(100));
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号