【发布时间】:2015-06-18 10:54:57
【问题描述】:
我有我想测试的程序:
while(true) {
//useful code
try {
id = inputValue();
} catch (InputMatchException e) {
System.out.println("blahblah");
}
}
public int inputValue() throws IOException {
InputStream inputStream = ???
System.setIn(inputStream);
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}
这里我希望 inputValue 在第一次迭代时返回字符串并导致 catch 块,第二次返回 0。有可能吗?循环有条件退出)不用担心。
【问题讨论】:
标签: java unit-testing