The following code works nicely when running the code through a main in Idea
System.in.read()
However the same code inside a junit method is not working
public void testConsoleRead()
{
System.in.read();
}
Any idea how to make this work, or something similar ?
You need to start the IDE with -Deditable.java.test.console=true
(e.g. via "Help" > "Edit Custom VM Options..."), see this comment.
You need to use the Scanner class.
First import it:
import java.util.Scanner
Now to use it:
Scanner scanner = new Scanner(System.in);
String text = scanner.next();
scanner.close();
There are more methods like scanner.nextLine();
that you should look at.
Also you might need to handle some Exceptions here but that's not difficult to figure out.