It took me a while to write a small application that calculates the standard weight, of course, the purpose is to test the use of robotium. After a period of soaking in robotium's API documentation, I also understood some basic operations, and began to try further.
robotium API:http://code.google.com/p/robotium/downloads/list
Although the API documentation has fully explained the relevant knowledge points, it is necessary to continue to use understanding to consolidate knowledge as learning.
The following is a brief introduction to some APIs
// Click a radio button
clickOnRadioButton(int index)
index: used to identify which RadioButton, there is only one RadioButton, index = 0 and so on
// Click on an EditText form
clickOnEditText(int index)
index: used to identify which EditText, there is only one EditText, index = 0 and so on
// Enter Text in EditText
enterText(int index, String text)
index: used to identify which EditText
text : the content of the input
// click a button
clickOnButton(String name)
name : the name of the button
// go back to the last page
goBack()
// Clear the EditText form
clearEditText(int index)
index: used to identify which EditText
- package com.luwenjie.standweight.test;
- import android.test.ActivityInstrumentationTestCase2;
- import com.luwenjie.standweight.StandWeightActivity;
- import com.jayway.android.robotium.solo.Solo;
- publicclass weightText extends ActivityInstrumentationTestCase2<StandWeightActivity> {
- private Only only;
- public weightText() {
- super ( "com.luwenjie.standweight" , StandWeightActivity.class ) ;
- }
- publicvoid setUp() throws Exception{
- solo = new Solo(getInstrumentation(), getActivity());
- }
- publicvoid testUI() throws Exception {
- boolean expected = true;
- //Verify that the standard weight of boy 180cm is 70kg
- solo.clickOnRadioButton(0);
- solo.clickOnEditText(0);
- solo.enterText(0, "180");
- solo.clickOnButton( "Calculate" );
- boolean actual1 = solo.searchText("70.00");
- assertEquals("This and/or is are not found", expected, actual1);
- //Return to clear the editText form
- solo.goBack();
- solo.clearEditText(0);
- //Verify that the standard weight of a girl 160cm is 70kg
- solo.clickOnRadioButton(1);
- solo.clickOnEditText(0);
- solo.enterText(0, "160");
- solo.clickOnButton( "Calculate" );
- boolean actual2 = solo.searchText("54.00");
- assertEquals("This and/or is are not found", expected, actual2);
- }
- }
This article is from the " Xiao Maozi " blog, please keep this source http://xiaomaozi.blog.51cto.com/925779/909558