Possible Duplicates:
Java, Junit - Capture the standard input / Output for use in a unit test
JUnit test for System.out.println()
I have written a piece of code similar to the one below. I want to unit test this method, and right now I am stuck at the System.out part. Lets say that the user input was 12. This would prompt the user with "Wrong number, try again.". Is it possible to test this output, or is this impossible by using JUnit?
public static int testUserInput() {
Scanner keyboard = new Scanner(System.in);
System.out.println("Give a number between 1 and 10");
int input = keyboard.nextInt();
while (input < 1 || input > 10) {
System.out.println("Wrong number, try again.");
input = keyboard.nextInt();
}
return input;
}
Thanks in advance.
No comments:
Post a Comment