Android automated testing - robotium (2) first acquaintance

 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

 

  1. package  com.luwenjie.standweight.test; 
  2.  
  3. import android.test.ActivityInstrumentationTestCase2; 
  4. import  com.luwenjie.standweight.StandWeightActivity; 
  5. import com.jayway.android.robotium.solo.Solo; 
  6.  
  7. publicclass weightText extends ActivityInstrumentationTestCase2<StandWeightActivity> {  
  8.     private  Only only; 
  9.     public weightText() { 
  10.         super ( "com.luwenjie.standweight" , StandWeightActivity.class )
  11.     } 
  12.      
  13.     publicvoid setUp() throws Exception{  
  14.          solo = new Solo(getInstrumentation(), getActivity());    
  15.     } 
  16.      
  17.     publicvoid testUI() throws Exception {  
  18.         boolean expected = true
  19.          
  20.         //Verify that the standard weight of boy 180cm is 70kg 
  21.         solo.clickOnRadioButton(0); 
  22.         solo.clickOnEditText(0); 
  23.         solo.enterText(0"180"); 
  24.         solo.clickOnButton( "Calculate" ); 
  25.         boolean actual1 = solo.searchText("70.00"); 
  26.         assertEquals("This and/or is are not found", expected, actual1); 
  27.          
  28.         //Return to clear the editText form 
  29.         solo.goBack(); 
  30.         solo.clearEditText(0); 
  31.          
  32.         //Verify that the standard weight of a girl 160cm is 70kg 
  33.         solo.clickOnRadioButton(1); 
  34.         solo.clickOnEditText(0); 
  35.         solo.enterText(0"160"); 
  36.         solo.clickOnButton( "Calculate" ); 
  37.         boolean actual2 = solo.searchText("54.00"); 
  38.         assertEquals("This and/or is are not found", expected, actual2); 
  39.     } 

 

This article is from the " Xiao Maozi " blog, please keep this source http://xiaomaozi.blog.51cto.com/925779/909558

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395974&siteId=291194637