Writing data to System.in

Mesut picture Mesut · Sep 28, 2010 · Viewed 19.4k times · Source

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?

Answer

jjnguy picture jjnguy · Sep 28, 2010

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