Robotium and Espresso Big pk--speed Chapter

Source: Internet
Author: User

Introduction

Espresso and Robotium are both Android UI Automation test frameworks and are open source libraries. Robotium, the most widely used testing framework in the early Android world, has expanded a number of effective testing methods for the Android UI based on JUnit.

Espresso is a new tool that, relatively speaking, is more accurate and helps developers write more concise UI test code for the app. Espresso's birth, the biggest advantage lies in "fast". In Robotium's test code, there is usually a lot of sleep,waitfor to wait for the control to load, otherwise it is very likely to fail. The espresso, however, does not have synchronization headaches and therefore greatly improves the test speed.

For most Android instrumentation-based test frameworks (Robotium), the test thread is independent of the UI thread, and espresso is different, and the runtime is automatically synchronized with the UI thread, so Espresso's actions and assertions operations run fast.

Below, let us together to feel "Fly general feeling"!

Test your phone: VIVO X520L--CPU: four cores; Memory: 3GB

Test object: Notepad--robotium sample test application with source code

Test content:

    1. New text note 1, save;
    2. New Text note 2, save;
    3. Check for note 1 and note 2 new success
    4. Click to enter note 1 text, use menu to delete;
    5. Long press note 2 to delete.
    6. Check Note 1 and note 2 Delete success

Test code

1. robotium test Code

 Public classNotepadrbotextendsActivityinstrumentationtestcase2<noteslist>{    PrivateSolo solo;  PublicNotepadrbot () {Super(Noteslist.class); }     Public voidTestaddnote ()throwsException {//New Note 1 and note 2, and determine if successfulSolo.clickonmenuitem ("Add Note"); Solo.entertext (0, "Note 1"); Solo.clickonmenuitem ("Save"); Solo.clickonmenuitem ("Add Note"); Solo.entertext (0, "Note 2"); Solo.clickonmenuitem ("Save"); Booleanexpected =true; Booleanactual = Solo.searchtext ("Note 1") && Solo.searchtext ("Note 2")); Assertequals ("Note 1 and/or note 2 is not found", expected, actual); //Delete Note 1 and note 2 and determine if the successSolo.clickontext ("Note 1"); Solo.clickonmenuitem ("Delete"); BooleanExpected2 =false; Solo.clicklongontext ("Note 2"); Solo.clickontext ("Delete"); BooleanActual2 = Solo.searchtext ("Note 1") | | Solo.searchtext ("Note 2"); Assertequals ("Note 1 and/or note 2 is found", Expected2, Actual2); }}

Robotium test Results

2. Espresso test Code

 Public classNotepadespextendsActivityinstrumentationtestcase2<noteslist>{     PublicNotepadesp () {Super(Noteslist.class); }     Public voidTestclickbutton ()throwsinterruptedexception {//Add Note1Onview (IsRoot ()). Perform (Viewactions.pressmenukey ()); Onview (Viewmatchers.withtext ("Add Note") . Perform (Viewactions.click ()); Onview (Viewmatchers.withid (R.id.note)). Perform (Viewactions.typetext ("Note 1"), Closesoftkeyboard ());        Onview (IsRoot ()). Perform (Viewactions.pressmenukey ()); Onview (Viewmatchers.withtext ("Save") . Perform (Viewactions.click ()); //Add Note2Onview (IsRoot ()). Perform (Viewactions.pressmenukey ()); Onview (Viewmatchers.withtext ("Add Note") . Perform (Viewactions.click ()); Onview (Viewmatchers.withid (R.id.note)). Perform (Viewactions.typetext ("Note 2"));        Onview (IsRoot ()). Perform (Viewactions.pressmenukey ()); Onview (Viewmatchers.withtext ("Save") . Perform (Viewactions.click ()); //Menu Delete Note1Onview (Viewmatchers.withtext ("Note 1")) . Perform (Viewactions.click ());        Onview (IsRoot ()). Perform (Viewactions.pressmenukey ()); Onview (Viewmatchers.withtext ("Delete") . Perform (Viewactions.click ()); Onview (Viewmatchers.withtext ("Note 2") . Perform (Viewactions.longclick ()); Onview (Viewmatchers.withtext ("Delete") . Perform (Viewactions.click ()); }}

Espresso Test Results

Summary

Robotium

Espresso

32.682 s

5.694 s

From the table, we can see clearly that executing the same test case, the espresso speed is 5.7 times times the robotium. Unlike the sleep/poll mechanism of robotium, the espresso is fully event-driven and the test thread synchronizes with the UI thread, with significant speed advantages.

Robotium and Espresso Big pk--speed Chapter

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.