I have a task to test a console application. I can access one method, but would also like to check that the string formatting is working correctly.
As this method does not return a string, but rather prints to the console, is there a way I can intercept the list printed line?
Does it even make sense to test this sort of thing?
Here is a sample how to catch output to the System.out:
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
System.setOut(new java.io.PrintStream(out));
System.out.println("Test output");
System.err.println("Out was: " + out.toString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With