Robotium code parsing: [java]/** This is an example test project created in Eclipse to test NotePad which is a sample * project located in AndroidSDK/samples/android-11/NotePad *** You can run these test cases either on the emulator or on device. right click * the test project and select Run As --> Run As Android JUnit Test ** @ author Renas Reda, renas.reda@jayway.com **/package com. jayway. test; impor T com. example. android. notepad. notesList; import com. jayway. android. robotium. solo. solo; import android. test. activityInstrumentationTestCase2; public class NotePadTest extends ActivityInstrumentationTestCase2 <NotesList >{< span style = "white-space: pre"> </span> private Solo solo; <span style = "white-space: pre "> </span> public NotePadTest () {<span style =" white-space: pre "> </span> super (NotesList. class); <Span style = "white-space: pre"> </span >}< span style = "white-space: pre "> </span> <span style =" white-space: pre "> </span> @ Override <span style =" white-space: pre "> </span> public void setUp () throws Exception {<span style =" white-space: pre "> </span> // setUp () is run before a test case is started. <span style = "white-space: pre"> </span> // This is where the solo object is created. <span style = "white-space: pre"> </Span> solo = new Solo (getInstrumentation (), getActivity (); <span style = "white-space: pre "> </span >}< span style =" white-space: pre "> </span> <span style =" white-space: pre "> </span> @ Override <span style =" white-space: pre "> </span> public void tearDown () throws Exception {<span style = "white-space: pre"> </span> // tearDown () is run after a test case has finished. <span style = "white-space: pre"> </span> // FinishOpenedActivities () will finish all the activities that have been opened during the test execution. <span style = "white-space: pre"> </span> solo. finishOpenedActivities (); <span style = "white-space: pre" ></ span >}< span style = "white-space: pre "> </span> public void testAddNote () throws Exception {<span style =" white-space: pre "> </span> solo. clickOnMenuItem ("Add note"); <span style = "white-space: pre"> </Span> // Assert that NoteEditor activity is opened <span style = "white-space: pre"> </span> solo. assertCurrentActivity ("Expected NoteEditor activity", "NoteEditor"); <span style = "white-space: pre"> </span> // In text field 0, add Note 1 <span style = "white-space: pre"> </span> solo. enterText (0, "Note 1"); <span style = "white-space: pre"> </span> solo. goBack (); <span style = "white-space: pre"> </span> // Clicks on Menu item <span style = "white-space: pre"> </span> solo. clickOnMenuItem ("Add note"); <span style = "white-space: pre"> </span> // In text field 0, add Note 2 <span style = "white-space: pre"> </span> solo. enterText (0, "Note 2"); <span style = "white-space: pre "> </span> // Go back to first activity named" NotesList "<span style =" white-space: pre "> </span> solo. goBackToActivity ("NotesList"); <span style = "white-space: Pre "> </span> // Takes a screenshot and saves it in"/sdcard/robobench-Screenshots /". <span style = "white-space: pre"> </span> solo. takeScreenshot (); <span style = "white-space: pre"> </span> boolean expected = true; <span style = "white-space: pre "> </span> boolean actual = solo. searchText ("Note 1") & solo. searchText ("Note 2"); <span style = "white-space: pre"> </span> // Assert that Note 1 & Note 2 are found <sp An style = "white-space: pre"> </span> assertEquals ("Note 1 and/or Note 2 are not found", expected, actual ); <span style = "white-space: pre"> </span >}< span style = "white-space: pre"> </span> public void testEditNote () throws Exception {<span style = "white-space: pre"> </span> // Click on the second list line <span style = "white-space: pre "> </span> solo. clickInList (2); <span style = "white-space: pre"> </span> // Change orientation of activity <span style = "white-space: pre"> </span> solo. setActivityOrientation (Solo. LANDSCAPE); <span style = "white-space: pre"> </span> // Change title <span style = "white-space: pre "> </span> solo. clickOnMenuItem ("Edit title"); <span style = "white-space: pre"> </span> // In first text field (0 ), add test <span style = "white-space: pre"> </span> solo. enterText (0, "test"); <span style = "white -Space: pre "> </span> solo. goBack (); <span style = "white-space: pre"> </span> boolean expected = true; <span style = "white-space: pre "> </span> <span style =" white-space: pre "> </span> // (Regexp) case insensitive <span style =" white-space: pre "> </span> boolean actual = solo. waitForText ("(? I ).*? Note 1 test "); <span style =" white-space: pre "> </span> // Assert that Note 1 test is found <span style =" white-space: pre "> </span> assertEquals (" Note 1 test is not found ", expected, actual); <span style =" white-space: pre "> </span> solo. <span style = "white-space: pre"> </span >}< span style = "white-space: pre"> </span> public void testRemoveNote () throws Exception {<span style = "white-space: pre"> </span> // (Rege Xp) case insensitive/text that contains "test" <span style = "white-space: pre"> </span> solo. clickOnText ("(? I ).*? Test. * "); <span style =" white-space: pre "> </span> // Delete Note 1 test <span style =" white-space: pre "> </span> solo. clickOnMenuItem ("Delete"); <span style = "white-space: pre "> </span> // Note 1 test & Note 2 shocould not be found <span style =" white-space: pre "> </span> boolean expected = false; <span style = "white-space: pre"> </span> boolean actual = solo. searchText ("Note 1 test"); <span style = "white-space: pre"> </Span> // Assert that Note 1 test is not found <span style = "white-space: pre"> </span> assertEquals ("Note 1 Test is found ", expected, actual); <span style = "white-space: pre"> </span> solo. clickLongOnText ("Note 2"); <span style = "white-space: pre "> </span> // Clicks on Delete in the context menu <span style =" white-space: pre "> </span> solo. clickOnText ("Delete"); <span style = "white-space: pre"> </span> actual = Solo. searchText ("Note 2"); <span style = "white-space: pre "> </span> // Assert that Note 2 is not found <span style =" white-space: pre "> </span> assertEquals (" Note 2 is found ", expected, actual); <span style =" white-space: pre "> </span >}1. robotium-solo-3.6.jar packages must be referenced in the Robotium project. [Java] public class NotePadTest extends ActivityInstrumentationTestCase2 <NotesList> 2. inherit from ActivityInstrumentationTestCase2 <NotesList>, define a solo object in the test project, and use this object for automated operations. [Java] private Solo solo; 3. Specify the main Activity in the program to be tested in the constructor, that is, view AndroidManifest in the source code of the project to be tested. the action attribute of the activity registered in the xml file is: <activity android: name = "NotesList" android: label = "@ string/title_notes_list"> <intent-filter> <action android: name = "android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> corresponds to the NotePad class in the NotePad project. [Java] public NotePadTest () {super (NotesList. class);} 4. The setUp () method is configured before the automation operation. [Java] @ Override public void setUp () throws Exception {solo = new Solo (getInstrumentation (), getActivity ();} 5, tearDown () method when the test case has been executed, close all activity events during the test. [Java] @ Override public void tearDown () throws Exception {solo. finishOpenedActivities () ;}6. Common Operations include click, hold, scroll screen, and set wait time. [Java] public void testAddNote () throws Exception {<span> </span> solo. clickOnMenuItem ("Add note"); <span> </span> // Assert that NoteEditor activity is opened <span> </span> solo. assertCurrentActivity ("Expected NoteEditor activity", "NoteEditor"); <span> </span> // In text field 0, add Note 1 <span> </span> solo. enterText (0, "Note 1"); <span> </span> solo. goBack (); <span> </span> // Clicks on menu item sol O. clickOnMenuItem ("Add note"); // Assert that NoteEditor activity is opened solo. assertCurrentActivity ("Expected NoteEditor activity", "NoteEditor"); // In text field 0, add Note 1 solo. enterText (0, "Note 1"); solo. goBack (); // Clicks on menu item solo. clickOnMenuItem ("Add note"); // In text field 0, add Note 2 solo. enterText (0, "Note 2"); // Go back to first activity named "NotesList" solo. goBackToAct Ivity ("NotesList"); // Takes a screenshot and saves it in "/sdcard/robobench-Screenshots /". solo. takeScreenshot (); boolean expected = true; boolean actual = solo. searchText ("Note 1") & solo. searchText ("Note 2"); // Assert that Note 1 & Note 2 are found assertEquals ("Note 1 and/or Note 2 are not found", expected, actual );} 7. assertEquals () verifies the actual results and expected results. If the actual results are inconsistent with the expected results, the test case fails to be executed and the test case is stopped. The example shows a test set composed of three use cases. When one of the test cases fails, the execution of other test cases is not affected. The Junit test results show detailed execution results and prompts about the cause of execution failure. The above is a basic analysis of the Android Robotium automated testing tool. You can debug some other functions.