I'm struggling to get Robotium to work on the gradle-based Android Studio and I can't find the way to do it
This is my build.gradle file
buildscript {
dependencies {
repositories {
mavenCentral()
mavenLocal()
}
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
/* maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}*/
}
sourceSets {
testLocal {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/resources')
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
}
sourceSets {
instrumentTest.setRoot('src/test')
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
// Dependencies for the `testLocal` task, make sure to list all your global dependencies here as well
testLocalCompile 'junit:junit:4.11'
testLocalCompile 'com.google.android:android:4.1.1.4'
testLocalCompile 'com.android.support:support-v4:13.0.+'
testLocalCompile 'org.robolectric:robolectric:2.1.+'
testLocalCompile 'com.jayway.android.robotium:robotium-solo:4.2'
// Android Studio doesn't recognize the `testLocal` task, so we define the same dependencies as above for instrumentTest
// which is Android Studio's test task
instrumentTestCompile 'junit:junit:4.11'
instrumentTestCompile 'com.google.android:android:4.1.1.4'
instrumentTestCompile 'com.android.support:support-v4:13.0.+'
instrumentTestCompile 'org.robolectric:robolectric:2.1.+'
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.2'
}
task localTest(type: Test, dependsOn: assemble) {
testClassesDir = sourceSets.testLocal.output.classesDir
android.sourceSets.main.java.srcDirs.each { dir ->
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join('/')
sourceSets.testLocal.compileClasspath += files(buildDir)
sourceSets.testLocal.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.testLocal.runtimeClasspath
}
check.dependsOn localTest
As you can see, I'm using Robolectric and Robotium The problem I've got is whenever I try to create a Robotium test, like this one:
import android.test.ActivityInstrumentationTestCase2;
import com.dlv.testing.MainActivity;
import com.jayway.android.robotium.solo.Solo;
public class MainActivityUITest extends
ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public MainActivityUITest() {
super(MainActivity.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testStuff() throws Exception {
solo.assertCurrentActivity("Check on first Activity", MainActivity.class);
solo.sendKey(Solo.MENU);
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
it cannot find any import, the project does not fail to compile in Android Studio, it just fails when I run the tests and if I remove the class and the references in the dependences, Robolectric works just fine