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?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
tin tin
  • 362
  • 1
  • 7
  • 19
  • Robotium wiki also has [a step-by-step guide for Android Studio](http://anirudh24seven.github.io/devlog/2015/02/13/robotium-android-studio.html) (posted long after the only answer here) – Andrew T. Jan 22 '17 at 10:06

1 Answers1

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"

Anirudh
  • 453
  • 2
  • 5
  • 18
bmv2143
  • 734
  • 1
  • 8
  • 17
  • The video link goes to this stackoverflow page – mrroboaat Jul 22 '14 at 12:02
  • @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. – bmv2143 Jul 22 '14 at 13:26
  • 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. – sdf3qrxewqrxeqwxfew3123 Nov 24 '14 at 16:07
  • @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. – bmv2143 Nov 24 '14 at 19:57