[Android automated testing: robobench] 02. robobench Case Analysis

Source: Internet
Author: User

If you have configured the test environment of robotium, let's get started (only the source code is introduced here, and you can do it without the source code)

Tested application download: http://download.csdn.net/detail/wirelessqa/4487252

Test code (only paste mainactivity and gridview, the use case is very simple and will not be commented out)

You can compare the use cases of athrun to see the differences between the two frameworks.


Package Org. onceler. robotium. test; import Java. util. arraylist; import Org. athrun. android. app. mainactivity; import Org. athrun. android. app. r; import Org. athrun. android. app. scrollactivity; import android. test. activityinstrumentationtestcase2; import android. test. suitebuilder. annotation. smoke; import android. util. log; import android. view. keyevent; import android. view. view; import android. widget. textview; import C Om. jayway. android. robotium. solo. solo; public class mainactivitytest extends activityinstrumentationtestcase2 <mainactivity> {private Solo; private textview TV; Private Static final string tag = "robotium_test"; Public mainactivitytest () {super ("org. athrun. android. APP ", mainactivity. class);} public void setup () throws exception {solo = new solo (getinstrumentation (), getactivity () ;}@ overridepublic Vo Id teardown () throws exception {// robotium will finish all the activities that have been openedsolo. finishopenedactivities () ;}@ smokepublic void testwaitforactivity () {solo. assertcurrentactivity ("assert activity Err", mainactivity. class); solo. assertcurrentactivity ("assert activity Err", "mainactivity"); solo. assertcurrentactivity ("assert activity Err", mainactivity. class, true); solo. assertcurrentacti Activities ("assert activity Err", "mainactivity", true); solo. clickonbutton ("scrollview"); solo. assertcurrentactivity ("assert activity Err", scrollactivity. class); solo. goback (); solo. clickonbutton (4); solo. assertcurrentactivity ("assert activity Err", "scrollactivity"); solo. gobacktoactivity ("mainactivity"); solo. assertcurrentactivity ("assert activity Err", "mainactivity", true) ;}@ smokepublic void testfindelem Entintree () {arraylist <View> List = solo. getviews (solo. getview (R. id. include_checkbox); TV = (textview) list. get (2); assertequals ("default text", TV. gettext (); solo. clickoncheckbox (0); TV = (textview) list. get (2); assertequals ("checkbox is checked! ", TV. gettext ();} public void testfindviewbyiddirect () {// get viewtv = (textview) solo by ID. getview (R. id. textview); assertequals ("default text", TV. gettext (); solo. clickoncheckbox (0); TV = (textview) solo. getview (R. id. textview); assertequals ("checkbox is checked! ", TV. gettext ();} public void testlongclick () {// imageview IV = (imageview) solo. getview (R. id. my_imageview); solo. clicklongonview (solo. getview (R. id. my_imageview); // The toast prompt cannot be captured. I don't know where the problem is. If you know it, please tell me. // assertequals (true, Solo. waitfortext ("longclick");} public void testpressmenu () {solo. clickonmenuitem ("toast"); // This toast is successful just like above. Oh my God, this is why assertequals (true, Solo. waitfortext ("Hello World");} public void testpresshome () {solo. sendKey (keyevent. keycode_home); solo. sleep (2000);} public void testpressback () {solo. clickonbutton ("scrollview"); solo. clickonbutton ("bottom button"); solo. sendKey (keyevent. keycode_back); solo. assertcurrentactivity ("assert activity Err", "mainactivity");} public void testfindviewbytext () {solo. clickonbutton (" Listview "); solo. clicklongontext (" item35 "); solo. clickontext (" item one "); asserttrue (Solo. waitfortext (" 1 pressed! ");} Public void testscrolllistindialog () {solo. clickonmenuitem ("dialog with List"); solo. clickontext ("item9"); asserttrue (solo. waitfortext ("item 9 clicked! "); Solo. clickonbutton (" OK "); asserttrue (Solo. waitfortext (" botton OK in dialog with list is pressed! ");} Public void testsetscreen () {solo. setactivityorientation (solo. landscape); solo. setactivityorientation (solo. portrait); solo. sleep (2000);} public void testgetstringbyid () {solo. clickonbutton ("scrollview"); asserttrue (solo. getstring (R. string. scroll_text ). tostring (). contains ("daoke");} public void testrequestfocus () {// it seems that there is no way to directly obtain the focus, so .. Move it slowly} public void testslide () {// The Gallery operation method does not have // Slide left and right with solo. scrolltoside (solo. left);} public void testgetchildcount () {log. I (TAG, String. valueof (solo. getviews (). size (); // The number of all views log. I (TAG, String. valueof (solo. getviews (solo. getview (R. id. mainroot )). size (); // number of views under linearlayout log. I (TAG, String. valueof (solo. getviews (solo. getview (R. id. my_gallery )). size (); // number of views in Gallery }}

Gridview


Package Org. onceler. robotium. test; import Org. athrun. android. app. gridviewactivity; import Org. athrun. android. app. listviewactivity; import android. test. activityinstrumentationtestcase2; import COM. jayway. android. robotium. solo. solo; public class gridviewactivitytest extends activityinstrumentationtestcase2 <gridviewactivity> {private Solo; Private Static final string tag = "robotium_test"; Public gridvie Wactivitytest () {super ("org. athrun. android. APP ", gridviewactivity. class);} public void setup () throws exception {solo = new solo (getinstrumentation (), getactivity () ;}@ overridepublic void teardown () throws exception {// robotify will finish all the activities that have been openedsolo. finishopenedactivities ();} public void testgetchildbyindex () {// solo. clickontext ("item.0"); solo. clickonimage (0); Assert True (Solo. waitfortext ("item 0 is clicked! "); Solo. assertcurrentactivity ("current activity is not listviewactivity", listviewactivity. class);} public void testgetchildbyindexmixed () {solo. clickontext ("item.19"); asserttrue (solo. waitfortext ("item 19 is clicked! "); Solo. sleep (1000); // There is no way to directly obtain the line of text next, so athrun can find solo through index. gettext (40); // there is a problem with this, the problem with the tested application // you can move to row 20th as below oh my god, so slow // For (INT I = 0; I <21; I ++) {// solo. sendKey (solo. down );//}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.