Android Development: "Gradle Recipes for Android" reading notes (translation) 5.3--using Robotium for functional testing

Source: Internet
Author: User

Problem:

You want to use the Robotium Library to test activity.

Solution:

Add robotium dependencies and write your own test scripts.

Discuss:

The Android Test Support library provides classes to manipulate the widgets in the activity, but has an easier way to manipulate the Android UI. Although this book is not an introduction to testing, it is easy to add robotium dependencies to Gradle and then run the tests.

The Robotium project is described as "selenium, but for Android". This is an automated test framework that makes it easy to write black-box UI tests for Android apps.

Just add the Robotium dependency in the Gradle configuration file below the module:

Consider the following simple activity called myactivity, prompting the user to enter a name, add it to intent, open the welcomeactivity Welcome User:

Robotium provides a called Com.robotium.solo.Solo, which includes the activity and instrumentation objects that are being tested. It allows you to add text, click Buttons, and more actions, without worrying about whether it is not on the UI thread. The following shows an example of activity:

The Robotium test inherits from ActivityInstrumentationTestCase2. The solo instance is initialized with the activity. Test the method of using the solo class, like Entertext,clickonbutton or SearchText.

The only drawback to using Robotium is to test the structure using the old JUnit3, with predefined setup and Teardown methods, all of which must conform to the public void testxyz format. In contrast, easy-to-write tests are still outstanding.

Test classes like other Android tests are easy to store under the androidtest structure. Execute on all emulators and connected devices through the Connectedcheck task.

The following shows the results of running on two emulators:

Click the "Devices" button to display the same results from the device angle:

Robotium's github address: Https://github.com/robotiumtech/robotium

Android Development: "Gradle Recipes for Android" reading notes (translation) 5.3--using Robotium for functional testing

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.