assertThat使用说明

来源:互联网 发布:外贸口语书籍推荐,知乎 编辑:程序博客网 时间:2024/05/18 04:27

所需要的jar包:junit-4.11.jar   hamcrest-core-1.3.jar   hamcrest-library-1.3.jar

assertThat方法所在的类为:org.junit.Assert,is方法所在的类为:org.hamcrest.Matchers,所以可以通过静态导入的方法来使用assertThat,

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

在函数中就可以直接写上assertThat(conf.get("color"), is("yellow"));如果conf.get("color")返回的是yellow,则控制台上没有任何输出,反之,会输出相应的错误。

原创粉丝点击