【发布时间】:2015-04-30 04:34:13
【问题描述】:
我必须测试别人无休止地运行但要求输入的方法:
public void automatize()
{
String cadena = new String();
while(true)
{
System.out.println("Executing...(Enter command)");
System.out.println("Enter Q to exit");
Scanner sc= new Scanner(new InputStreamReader(System.in));
cadena=sc.nextLine();
if(cadena.toLowerCase().equals("q"))
break;
String[] command = str.split(" ");
if(comando.length!=0)
new Extractor().run(command);
}
}
我应该如何使用 JUnit 进行测试?
这是我试图做的,但是,它实际上并没有做任何事情:
@Test
public void testAutomatize_q() {
ByteArrayInputStream in = new ByteArrayInputStream("Q".getBytes());
System.setIn(in);
extractor.automatize();
System.setIn(System.in);
}
【问题讨论】: