Go Build an automated test framework in Android Studio Robotium

Source: Internet
Author: User
Tags home screen

Android's automated testing framework is not much to choose from, then Robotium (https://code.google.com/p/robotium/), its syntax and ease of use is quite like the kif we use in iOS.

The official document does not mention how to build it in Android Studio, and later found an answer in stack overflow: http://stackoverflow.com/questions/23275602/ robotium-with-android-studio/23295849#23295849

In my own analysis, it is quite simple to build Robotium in Android Studio:

1, Build.gradle, dependencies under increase Androidtestcompile ' com.jayway.android.robotium:robotium-solo:5.1 '. If this configuration is missing, the Robotium package will not be available in the test code.

2, the code structure of our project is old-fashioned, so we need to re-set the test address, that is, under android.sourcesets new Androidtest.setroot (' tests '). You can take other names outside of tests, and then set up this folder in the same class as build.gradle, without any additional settings, the test code placement needs to follow the new structure, that is, Tests\java. If it is not configured correctly, the test code will not be visible.

In addition to the code changes, if you want to run in Android Studio, you also need additional configuration: Menu run, Edit configuration, the new entry under Android tests, and then properly configured, you can: choose which module, Select the range of tests (module or package, etc.) and select Target Device. This is a configuration thing and there is no way to commit to git.

Here is a simple example, our app in the test environment will first pop up a selected environment Alertdialog, so need to Clickontext:

  1. /**
  2. * Created by Samuel Cai on 5/20/14.
  3. */
  4. Public class Mainactivitytest extends ActivityInstrumentationTestCase2 {
  5. private solo solo;
  6. Public mainactivitytest () {
  7. super (logoactivity.   Class);
  8. }
  9. @Override
  10. public void SetUp () throws Exception {
  11. Super.setup ();
  12. Solo = new solo (Getinstrumentation (), getactivity ());
  13. }
  14. public void Testnavigatetohomescreen () throws Exception {
  15. //choose Environment
  16. Solo.waitfordialogtoopen ();
  17. Solo.clickontext ("QA");
  18. Solo.clickonbutton ("OK");
  19. //assert Home screen finished loading.
  20. Asserttrue (Solo.waitfortext ("diapering"));
  21. }
  22. }

Transferred from: http://m.blog.csdn.net/blog/hongaiyan/39676657#

Go Build an automated test framework in Android Studio Robotium

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.