简体   繁体   中英

How to use Robotium with Android Studio?

Robotium is an Android test automation framework that has full support for native and hybrid applications.

Now that Android Studio is the de facto IDE for Android development, I'm interested to try this with Android Studio. However, I couldn't find a way to set it up.

How to setup and use Robotium to test with Android Studio?

Guide:

  1. Add the following line to the dependencies section of the inner build.gradle file (this file is located at the same level as src folder), change version name if required:

     androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1' 

    If for some reason you don't want to let gradle download dependencies for you then you can add them manually: Place robotium.jar into the libs folder. Right click it and select Add as library...

  2. In the src folder create another folder androidTest

  3. Inside it create java folder
  4. (Optional step, see below) Inside it create a package for the test source with the same name as app's package name (or add ".tests" to its end.)
  5. Place cursor (in the Editor window) at the class name inside one of the files that you want to test (eg MainActivity) and press Alt+Enter.
  6. Select Create Test . Select the proper superclass for Robotium:

     android.test.ActivityInstrumentationTestCase2 
  7. Android studio will create a test file and a package (if it wasn't created in step 6)
  8. How to run the test:

    • UI: as usual using Android Studio Run menu
    • console: in the terminal enter the following command:

       ./gradlew connectedAndroidTest 

      The HTML-reports will be generated at "YourApp/YourApp/build/outputs/reports/androidTests/ connected/index.html"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM