org.junit.contrib.java.lang.system.SystemOutRule

来源:互联网 发布:淘宝李维斯代购 编辑:程序博客网 时间:2024/06/05 20:08

使用Junit-4.12时测试时用到 org.junit.contrib.java.lang.system.StandardOutputStreamLog;提示找不到这个包;原因是Junit-4.12中没有这个包。

可以使用System Rules的一个Junit规则 org.junit.contrib.java.lang.system.SystemOutRule,该规则能够基于控制台的输出编写断言。

我们需要下载system-rules-1.16.0.jar这个jar包;下载链接:http://stefanbirkner.github.io/system-rules/   点击页面上方的Get System Rules按钮下载。

使用方法如下:

public void MyTest {@Rulepublic final SystemOutRule systemOutRule = new SystemOutRule().enableLog();@Testpublic void writesTextToSystemOut() {System.out.print("hello world");assertEquals("hello world", systemOutRule.getLog());}}


1 0
原创粉丝点击