我试图为一个需要用户输入的方法创建一些 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;
}
有没有一种可能的方法来自动传递程序一个 int,而不是我或其他人在 JUnit 测试方法中手动这样做?比如模拟用户输入?
先谢谢你。