javajunitiosystem.in

Writing data to System.in


In our application, we expect user input within a Thread as follows :

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

I want to pass that part in my unit test so that I can resume the thread to execute the rest of the code. How can I write something into System.in from junit?


Solution

  • What you want to do is use the method setIn() from System. This will let you pass data into System.in from junit.