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?
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?
Yes you can, you could change the default System.out to a file, a buffer, etc. and unit test that new stream for the expected data. But IMO that's a terrible terrible idea.
Other aproach woud be using a Logger instead the standard output and unit test the log, but once again it sounds weird unit testing a logger. At least if you are not developing a logging tool :)
To me it sounds like a bad understanding of what is unit testig, but I could be wrong.
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.