System.out.print()在测试方法中没有显示任何内容 [英] System.out.print() doesn't show anything in test methods

查看:500
本文介绍了System.out.print()在测试方法中没有显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在单元测试中使用 System.out 打印一些数据( @Test mehotds) ,但它没有显示任何东西。但是,它在 @Before 方法中正常工作。我正在使用JUnit和Maven Surefire插件。

I'm trying to print some data with System.out in my unit tests (@Test mehotds), but it is not showing anything. However, it works properly in @Before method. I'm using JUnit with Maven Surefire plugin.

public class MyTests {

  @Before
  void init(){

    System.out.println("Initializing some data..."); // <- It works.

  }

  @Test
  void shouldRemoveSeries() {

    System.out.println("TEST: Should remove series"); // <- It doesn't.

  }
}

maven -surefire-plugin 配置:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.15</version>
  <configuration>
    <includes>
      <include>**/*Tests.java</include>
    </includes>
  </configuration>
</plugin>

谢谢。

推荐答案

使用日志

private static Logger log = Logger.getLogger(LoggingObject.class);
log.info("I'm starting");

System.setOut()

private final PrintStream stdout = System.out;
private final ByteArrayOutputStream output = new ByteArrayOutputStream();
private TerminalView terminalview;

这篇关于System.out.print()在测试方法中没有显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆