0

I've been read this question here to learn how to redirect standard output into a char array so it can be compared to the expected output, however when doing so, everything after that declaration is redirected, meaning I can't actually get anything else to print to the console and therefore check that the unit test is successful or not. Is there any way to have the output of either a) only certain methods redirected to an array or b) having the scope of the redirected output limited in some way? Thanks!

Community
  • 1
  • 1
Imamadmad
  • 77
  • 1
  • 11

1 Answers1

0

You can save the old output stream, then redirect it the way you want, do your test and restore it by calling System.setOut(yourSavedValue).