如何使用黄瓜和阿鲁巴测试交互式Java应用程序
我有这个Cucumber / Aruba场景:
Scenario: Simple echo
Given I run `java -cp /bin Echo` interactively
When I type "something\n"
Then the output should contain "something"
测试这个简单的java程序:
import java.util.*;
class Echo {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.println(stdin.next());
}
}
当我运行测试时,它失败了,我收到以下错误:
Then the output should contain "something"
expected "" to include "something" (RSpec::Expectations::ExpectationNotMetError)
features/cli.feature:15:in `Then the output should contain "something"'
当我尝试使用这个ruby程序进行相同的测试时:
puts gets
全是绿色......
我在这里做错了吗?
是否必须使用其他方法从标准输入读取? System.in仅用于键盘吗?
答案 0 :(得分:0)
你可以尝试一些事情:
首先测试Cucumber / Aruba是否通过强制输出符合您在测试中的预期来获取System.out.println调用:即
System.out.println("something");
如果这样可行,那么你在阅读标准输入时是否正确(我从未见过有人从标准输入读取你的方式)。下面的答案是我通常看到人们从Java中读取标准输入: