org.junit.contrib.java.lang.system.StandardOutputStreamLog在哪里?

时间:2015-12-31 07:55:12

标签: java junit4

这堂课在哪里? 我的项目使用JUnit 4.12,而没有找到StandardOutputStreamLog。 是否会在此版本中删除? 或者它来自另一个lib?这两个之间的关系是什么?

enter image description here

5 个答案:

答案 0 :(得分:10)

@ pahul Tripathi建议

SystemOutRule取代StandardOutputStreamLog

只需添加更多指针即可立即开始使用。

Maven依赖:

<dependency>
    <groupId>com.github.stefanbirkner</groupId>
    <artifactId>system-rules</artifactId>
    <version>1.18.0</version>
    <scope>test</scope>
</dependency>

将jar添加到buildpath以获取以下导入。

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

public void MyTest {
    @Rule
    public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();

    @Test
    public void writesTextToSystemOut() {
        System.out.print("hello world");
        assertEquals("hello world", systemOutRule.getLog());
    }
}

参考:http://stefanbirkner.github.io/system-rules/

答案 1 :(得分:6)

不推荐使用StandardOutputStreamLog()。它是JUnit 4.x包中不存在的类。我谷歌这个类加上单词maven就像这样:org.junit.contrib.java.lang.system.StandardOutputStreamLog()+ maven我发现它没有在junit Maven Repository中定义,而是在com.github.stefanbirkner中定义。所以通过添加maven坐标

<dependency>
    <groupId>com.github.stefanbirkner</groupId>
    <artifactId>system-rules</artifactId>
    <version>1.16.0</version>
</dependency>

您应该能够解决问题。

答案 2 :(得分:4)

此类已弃用,您应使用SystemOutRule

检查source

  

StandardOutputStreamLog()

     

已弃用。

     

请使用新的SystemOutRule()。enableLog()。

     

创建一条规则,在写入仍然写入时写入   标准输出流。

答案 3 :(得分:1)

如果您使用gradle,则可以在 build.gradle 文件中添加以下依赖关系规则。

{{1}}

您应该能够解决问题。

答案 4 :(得分:-1)

我也有这个问题,事实是JUnit 4.12库没有包org.junit.contrib.java.lang.system。您需要的库是系统规则。要解决此问题,您可以搜索google&#34;系统规则Junit&#34;然后找到下载库的链接。例如,现在可以在此link

下载

我希望这会对某人有所帮助。