Java, Junit - Capture the standard input / Output for use in a unit test?

Use System.setOut() (and System.setErr() ) to redirect the output to an arbitrary printstream - which can be one that you read from programmatically.

Use System.setOut() (and System.setErr()) to redirect the output to an arbitrary printstream - which can be one that you read from programmatically. For example: final ByteArrayOutputStream myOut = new ByteArrayOutputStream(); System. SetOut(new PrintStream(myOut)); // test stuff here... final String standardOutput = myOut.toString().

So simply going PrintStream _out = System. Out; Won't work? – Frank V Jan 30 '10 at 20:37 It would - i.e.

You'd have a reference to the existing output stream - but you can't read anything from it as there are no appropriate methods to do so on the general PrintStream interface. The technique involves setting the output to a specific printstream you know how to read from. – Andrzej Doyle Jan 30 '10 at 20:38.

The System class has methods setIn(), setOut() and setErr() that allow you to set the standard input, output and error streams, e.g. To a ByteArrayOutputStream that you can inspect at will.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send