turn from: hereA
summary of common robotium test questions: 1,robotium test class ActivityInstrumentationTestCase2 inherit TestCase class, that is, Robotiom test class is junit3 instance, and there is no junit4 characteristics, For example, through the annotate way to identify the new characteristics of subclasses, not to achieve @beforeclass, @afterclass and other characteristics. You can only test case writing by writing setup and teardown, as well as test cases that begin at test. 2, some buttons do not have a string, no text, only through the index to click this is not intuitive, and the button's index is not fixed, it is possible to reload with the control, the order can also change, can not guarantee the test results. Viewed the Robotium source code, found that most of the click methods are eventually converted to view by passing in parameters, and then call Clickonview, so the reference to write a button ID to click the method. The ID of the button needs to be retrieved from the source of the test object. For example, the navigation has a menu bar, most of which is this type of button. 3. Some activity can not get the focus after clicking, may get activity content in another way, such as activity act = solo.getcurrentactivity (); Get Current activity, Then get the control by Act.findviewbyid. 4, multiple screen situation, you can scroll through the way of sliding, solo.scrolltoside (solo.left), if the multi-screen belongs to an activity, you do not need to swipe to run case to obtain data. 5. Sometimes the click method of text View or button will fail. The answer is in the Androidmanifest.xml file of the program under test to add such a sentence: <supports-screens android:anydensity= "true"/> on the line. 6. If you want to read and write SD card swelling in Robotium test program? The answer is to add in the Androidmanifest.xml file of the program under test.<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission> <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission>. Note that it is added in the test procedure, the manifest file in the testing program itself will be very pit daddy. 7, ListView Dynamic Add Item How to determine the success of the Add. From before and after the addition of the item count, determine the property to add item, and then the corresponding method to get item. For example, adding an item may require three TextView, so the difference between getcurrenttextviews (View) before and after it is three. For example, add blacklist to blacklist list. (1) Some ListView only Web, or mainly text, can be obtained by getitematposition (i). ToString () method to get the contents of the first few lines. Solo.clickontext (Chooseprovpage.getlistview (). Getitematposition (i). toString ());(2) Some ListView contains multiple TestView or buttons, which can be used to get the contents of a line in a Findviewbyid way. 8, unable to catch toast, this is a little confused. Probably experiment, can use waitfortext this function to capture the text, this method return value is Boolean type, so return true is found. 9. Result Judgment(1) waitfortextThis method is useful for judging the result after a click operation takes a little time to return the result. such as networking operations, you can set the appropriate delay, wait for the return result, the result is more correct. (2) assertactivityThis method is suitable for activity, can determine whether the click operation is correct to switch activity, can be used in conjunction with Waitfortext. (3) Searchtext+assertWhen there is a edittext, after entering the content, you can find out whether the input is the expected result by SearchText, and then return the result to judge. Note: Some edittext content cannot pass the searchtext, reason is not found temporarily. For example: the name and number of the input box when adding a blacklist manually. viii. operation of the Robotium project: There are two ways, one is through eclipse; one is through the command line. 1. EclipseRun as Android JUnit test, you can run the entire test project, you can also run a single test case. 2. Command lineadb install ****test.apkadb shell am Instrument testpackagename/android.test.instrumentationtestrunner
A summary of common Robotium test questions: