您好我正在尝试测试编辑文本放置2个不同的值,但第二个测试失败。原因未知...下面是我的代码 的 TestCase1
public void testvalues1() {
// clearing the edit text
mTextView.clearComposingText();
TouchUtils.tapView(this, mTextView);
// sending input as 7
sendKeys("7");
String userInput1;
String expected = "158269.3778";
String parameterFrom1 = "0.0027";
String parameterTo1 = "61.04676";
// getting the input from the mTextView reference
userInput1 = mTextView.getText().toString();
String resultset = UnitCalculation.Converter(parameterFrom1,userInput1,parameterTo1);
assertEquals(resultset, expected);
}
在上面的测试案例中,iam发送值7并且输出是预期的
TestCase2
public void testvalues2() {
// clearing the edit text
mTextView.clearComposingText();
TouchUtils.tapView(this, mTextView);
// sending input as 23
sendKeys("23");
String userInput1;
String expected = "150.5011";
String parameterFrom1 = "1.092607";
String parameterTo1 = "7.149502";
// getting the input from the mTextView reference
userInput1 = mTextView.getText().toString();
String resultset1 = UnitCalculation.Converter(parameterFrom1,userInput1,parameterTo1);
System.out.println("printing resilt set "+ resultset1);
assertEquals(resultset1, expected);
}
但该方法返回值0而不是150.5011 我使用相同的方法计算,当我给用户值硬编码像这样字符串userInput1 =" 23&#34 ;; 它正在工作,但是当从edittext获取值时它不是工作。
我可以发送多个值来编辑同一个测试文件上的文本吗?
答案 0 :(得分:0)
sendKeys
搞砸了它。请参阅this reference。
总之,sendKeys
需要一个包含空格分隔键的String。您的sendKeys("23")
正试图在名为23
的软键盘中找到一个键,尽管没有。试试这个:
sendKeys("2 3");
因为它将单独发送这两个击键,而不是试图找到名为23
的键。这就是为什么只发送一个7
,因为7
是“7”的关键名称。