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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34543108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:01:14  来源:igfitidea点击:

Where is the org.junit.contrib.java.lang.system.StandardOutputStreamLog?

javajunit4

提问by Oolong

Where is this class? My project use the JUnit 4.12, and not found the StandardOutputStreamLog. Is it be removed at this release? or it come from the other lib? and what is the relation between these tow?

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

enter image description here

在此处输入图片说明

采纳答案by Rahul Tripathi

This class is deprecated and you should use SystemOutRule.

此类已弃用,您应该使用SystemOutRule

Check the source

检查来源

StandardOutputStreamLog()

Deprecated.

Please use new SystemOutRule().enableLog().

Creates a rule that records writes while they are still written to the standard output stream.

标准输出流日志()

已弃用。

请使用 new SystemOutRule().enableLog()。

创建一个规则,记录写入时仍写入标准输出流。

回答by KurinchiMalar

SystemOutRulesuperseded StandardOutputStreamLogas suggested by @Rahul Tripathi.

SystemOutRuleStandardOutputStreamLog按照@Rahul Tripathi 的建议取代。

Just adding few more pointers to get started right away.

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

Maven dependency:

Maven 依赖:

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

Add the jar to the buildpath to get the below import.

将 jar 添加到构建路径以获取以下导入。

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

Reference: http://stefanbirkner.github.io/system-rules/

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

回答by Elom Atsou Agboka

StandardOutputStreamLog() is not deprecated. It's a class that's not present in the JUnit 4.x package. I google this class plus the word maven like so : org.junit.contrib.java.lang.system.StandardOutputStreamLog() + maven and I found that it is not define in the junit Maven Repository but instead in the com.github.stefanbirkner. So by adding the maven coordinate

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

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

You should be able to resolve the problem.

您应该能够解决问题。

回答by shen ke

If you use gradle, you can add the following dependency rules in your build.gradlefile.

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

dependencies {
testCompile "com.github.stefanbirkner:system-rules:${systemRulesVersion}"}

You should be able to resolve the problem.

您应该能够解决问题。

回答by inalkimia

I had this problem too, the fact is that the library JUnit 4.12 don't have the package org.junit.contrib.java.lang.system. The library that you need is system-rules. For to solve this, you can search on google "system-rules Junit" and then found the links for to download the library. For example now is available to download in this link

我也有这个问题,事实是库 JUnit 4.12 没有 package org.junit.contrib.java.lang.system。您需要的库是系统规则。为了解决这个问题,你可以在谷歌上搜索“system-rules Junit”,然后找到下载库的链接。例如现在可以在此链接中下载

I hope this will help to someone.

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