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