Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

java - System.out.print() doesn't show anything in test methods

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 configuration:

<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>

Thanks.

question from:https://stackoverflow.com/questions/29488900/system-out-print-doesnt-show-anything-in-test-methods

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ran into this as well. I'm using gradle to manage my tasks and I put this in at the end of by build.gradle file :

test {
  testLogging.showStandardStreams = true
}

Now I see System.out.println(whateves).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...