Possible Duplicate:
JUnit test for System.out.println()
Is it possible to check, through JUnit testing, if the method System.out.println(“One, Two”), actually prints One, Two?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A better idea would be to change your application to be more testable by not using System.out directly.
If the method you are trying to test is designed to write output for end users, modify it or the enclosing class so that the destination OutputStream or PrintWriter or whatever is a parameter.
On the other hand, if the method is producing log output, use a proper logging framework … and consider whether it is worthwhile to unit test the log output at all.