I am trying to use JUnit to test a java application which takes input from the console to make choices in the program. Here is a snippet of the program I am trying to test below.
PS: I am new to JUnit testing so a clear and simple answer would be appreciated.
public void mainMenu(){
String input;
while (true){
System.out.println("1. view 2. Set-Up 3. Exit");
input = getInputFromConsole().trim();
switch (input.charAt(0)) {
case '1':
view();
break;
case '2':
setUp();
break;
case '3':
System.exit(0);
break;
}
}
How would I create a test case where the input would be eg. '1' but the input is given from the console?