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);
}
}