JUnit test for System.out.println()

前端 未结 13 1722
广开言路
广开言路 2020-11-22 03:18

I need to write JUnit tests for an old application that\'s poorly designed and is writing a lot of error messages to standard output. When the getResponse(String reque

13条回答
  •  失恋的感觉
    2020-11-22 04:10

    You can set the System.out print stream via setOut() (and for in and err). Can you redirect this to a print stream that records to a string, and then inspect that ? That would appear to be the simplest mechanism.

    (I would advocate, at some stage, convert the app to some logging framework - but I suspect you already are aware of this!)

提交回复
热议问题