5

I'm struggling to get Robotium to work on the gradle-based Android Studio and I can't find the way to run the test with gradle CLI. I Placed robotium.jar "robotium-solo-5.4.1.jar" into the libs folder, Added as library. In the src folder I created another folders androidTest->java->package for the test source with the same name as app’s package name-> Test.java "java" (inside "androidTest") is a green color.

UI: as usual using Android Studio Run menu - working.

console: in the terminal enter the following command: gradlew connectedAndroidTest = not working. I also tried "gradlew test", test results get generated in build/test-report, but they show that no tests were found.

I want to run Robotium test with gradle CLI without connecting device, because I want to run tests in the Android emulator in CircleCI.

Is there a problem on my build.gradle / test file or is there a something I missing ?

I would really appreciate any help!

***** This is my build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    dexOptions {
//        jumboMode true
        javaMaxHeapSize "2g"
    }

    defaultConfig {
        applicationId 'net.example'
        minSdkVersion 14
        targetSdkVersion 22
        versionName '2.8.1'
        versionCode 2801
        multiDexEnabled true
    }
    buildTypes {
        debug{
            debuggable true
            jniDebuggable true
        }
        release {
            debuggable false
            jniDebuggable false
            minifyEnabled true
            proguardFiles 'proguard-coda.txt', 'proguard-rules.pro'
        }
    }
    productFlavors {

    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    lintOptions {
        disable 'MissingTranslation'
    }

    sourceSets {
        androidTest {
            java.srcDirs = ['src/androidTest/java']
        }
    }
}

dependencies {

// Included library modules
    ...

// My regular dependencies
    ...
    compile fileTree(include: ['*.jar'], dir: 'libs')

// Test dependencies
    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.4.1'
    androidTestCompile fileTree(dir: 'libs', include: 'robotium-solo-5.4.1.jar')
}

***** Robotium test file in the Location : app->src->androidTest->java->package name->Test.java

package net.example;

import com.robotium.solo.*;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import java.util.ArrayList;

@SuppressWarnings("rawtypes")

public class Test extends ActivityInstrumentationTestCase2 {

    private Solo solo;

    //Debug Logcat Tag for filtering
    private static final String TAG = "RoboDebug";

    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME ="net.example.exampleActivity";

    private static Class<?> launcherActivityClass;
    static{
        try {
            launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    public Test() throws ClassNotFoundException {
        super(launcherActivityClass);
    }

    public void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation());
        getActivity();
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();
    }

    public void testRun() {
        //Wait for activity: 'net.example.exampleActivity'
        solo.waitForActivity("exampleActivity", 5000);
        //Wait for activity: 'coda.RootActivity'
        //!!!!!!!!
        assertTrue("RootActivity is not found!", solo.waitForActivity("RootActivity"));
        //Set default small timeout to 60000 milliseconds
        //Click on Beauty
        solo.clickOnText(java.util.regex.Pattern.quote("Beauty"));
        ArrayList<View> dig = solo.getViews();
        android.util.Log.d(TAG, "Dig is: " + dig);


    }
}
  • Please see this [link](http://stackoverflow.com/questions/16586409/how-can-i-create-tests-in-android-studio/20348909#20348909). Let us to know if it helps. – Eugene Jun 06 '15 at 16:51
  • thanks, i made some changes, now when I run "gradlew connectedAndroidTest" I can see the test report but its fail on : " junit.framework.AssertionFailedError: Text string: '\QBeauty\E' is not found! at com.robotium.solo.Clicker.clickOnText(Clicker.java:451) at com.robotium.solo.Solo.clickOnText(Solo.java:1473) at net.example.Test.testRun(Test.java:53) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) " , is it something with the test code now ? –  Jun 07 '15 at 20:15
  • Following your error this means that the word "Beauty" not found on the page. Please ensure that it's there and in quotes. – Eugene Jun 08 '15 at 06:35
  • @LiranGabay Did you find a solution? I have the same problems in my CI server, but you can avoid this issue with compileSdkVersion 21 and buildToolsVersion "21.1.2" – Gorets Jul 10 '15 at 13:50

0 Answers0