首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnitTesting for EditText,测试多个值

UnitTesting for EditText,测试多个值
EN

Stack Overflow用户
提问于 2014-11-26 08:48:26
回答 1查看 338关注 0票数 0

嗨,我正在尝试测试编辑文本,放置两个不同的值,但是第二个测试失败了,.reasons unknown...below是我的代码TestCase1

代码语言:javascript
复制
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

代码语言:javascript
复制
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 Iam,当我给出像这个字符串userInput1=“23”这样的硬编码的用户值时;是工作的,但是当从编辑文本中获取值时,它是无效的。

我可以发送多个值来编辑同一个测试文件上的文本吗??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-26 09:24:35

有多个字符的sendKeys是搞砸它的原因。见本参考

总之,sendKeys需要一个包含空格分隔键的字符串。您的sendKeys("23")正在尝试在名为23的软键盘中找到一个键,尽管没有。

代码语言:javascript
复制
sendKeys("2 3");

因为它将分别发送这两个键笔画,而不是试图找到一个名为23的键。这就是为什么只发送一个7的原因,因为7是"7“的关键名称。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27144709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档