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

前端 未结 8 1256
春和景丽
春和景丽 2020-12-14 15:28

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

相关标签:
8条回答
  • 2020-12-14 15:50

    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;
    
    0 讨论(0)
  • 2020-12-14 15:54

    This sound familiar to me, so I assume you're running your tests from some IDE (Netbeans?). It might be the case that it only shows the output for tests that fail. Does this also occur when running the test from console?

    You might have more luck using System.err instead of System.out, but I'm not sure about this.

    0 讨论(0)
提交回复
热议问题