How to use Robotium with Android Studio?
Asked Answered
K

1

21

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?

Kittie answered 24/4, 2014 at 17:18 Comment(1)
Robotium wiki also has a step-by-step guide for Android Studio (posted long after the only answer here)Collimore
M
40

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 (e.g. 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"

Malinin answered 11/6, 2014 at 7:19 Comment(4)
The video link goes to this stackoverflow pageExaggeration
@aat thank you for your remark. There was another answer in this thread that had a link to some live code event that talked about this topic. That answer was removed and unfortunately the video is not available anymore. I fixed my answer.Malinin
Why do you need to add robotium.jar manually to your libs (step 1)? If you add dependency as in step 3 gradle should automatically resolve dependency from maven central.Lemberg
@lenrok258 thank you for your remark! You are absolutely right. It is better to let gradle handle dependencies instead of doing it manually. Updated my answer.Malinin

© 2022 - 2024 — McMap. All rights reserved.