javamavenjunit

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.


Solution

  • Use Log

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

    or System.setOut()

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