?花了一点时间写了一个计算标准体重的小应用,当然目的是为了测试 robotium 的使用情况。经过一段泡在robotium的API文档上,对一些基本操作也有所了解,开始了更进一步的尝试。
robotium API:http://code.google.com/p/robotium/downloads/list
虽然API文档已经把相关知识点解释的很全,作为学习还需不断使用理解巩固知识
以下先简单介绍一部分API
?
// 单击一个单选按钮
clickOnRadioButton(int index)
index:用来标识哪个RadioButton, 只有1个RadioButton,index = 0 以此类推
?
// 单击一个EditText表单
clickOnEditText(int index)
index: 用来标识哪个EditText,只有1个EditText, index = 0 以此类推
?
// 在EditText中输入Text
enterText(int index, String text)
index: 用来标识哪个EditText
text : 输入的内容
?
// 单击一个按钮
clickOnButton(String name)
name : 按钮的名称
?
// 返回上一页
goBack()
?
// 清空EditText表单
clearEditText(int index)
index: 用来标识哪个EditText
?
- package?com.luwenjie.standweight.test;?
- ?
- import?android.test.ActivityInstrumentationTestCase2;?
- import?com.luwenjie.standweight.StandWeightActivity;?
- import?com.jayway.android.robotium.solo.Solo;?
- ?
- public?class?weightText?extends?ActivityInstrumentationTestCase2<StandWeightActivity>?{?
- ????private?Solo?solo;?
- ????public?weightText()?{?
- ????????super("com.luwenjie.standweight",?StandWeightActivity.class);?
- ????}?
- ?????
- ????public?void?setUp()?throws?Exception{?
- ?????????solo?=?new?Solo(getInstrumentation(),?getActivity());????
- ????}?
- ?????
- ????public?void?testUI()?throws?Exception?{?
- ????????boolean?expected?=?true;?
- ?????????
- ????????//验证男孩180cm的标准体重为70公斤?
- ????????solo.clickOnRadioButton(0);?
- ????????solo.clickOnEditText(0);?
- ????????solo.enterText(0,?"180");?
- ????????solo.clickOnButton("计算");?
- ????????boolean?actual1?=?solo.searchText("70.00");?
- ????????assertEquals("This?and/or?is?are?not?found",?expected,?actual1);?
- ?????????
- ????????//返回清空editText表单?
- ????????solo.goBack();?
- ????????solo.clearEditText(0);?
- ?????????
- ????????//验证女孩160cm的标准体重为70公斤?
- ????????solo.clickOnRadioButton(1);?
- ????????solo.clickOnEditText(0);?
- ????????solo.enterText(0,?"160");?
- ????????solo.clickOnButton("计算");?
- ????????boolean?actual2?=?solo.searchText("54.00");?
- ????????assertEquals("This?and/or?is?are?not?found",?expected,?actual2);?
- ????}?
- }?
?
本文出自 “小毛子” 博客,请务必保留此出处http://xiaomaozi.blog.51cto.com/925779/909558