Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...