Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Integration Testing on Android with the new Gradle Build System?

Our Android app needs automated testing, and our group is using Robotium to handle that for us. This is no problem for unit tests, but we're also writing a set of end-to-end integration tests to exercise not only the client by the back-end servers as well. I've got some tests that do this, but if possible, I'd like to break them out separately from the unit tests so that our continuous integration builds don't require a live server to be running in order to complete.

We're using the shiny new Gradle build system. I'm wondering if I could do something like a test-only flavor or a subproject that depends on the parent APK to make it go. I tried making this work with a separate project altogether using the Robotium instructions for testing a source-less debug APK, but it didn't work. Maybe because I was on real hardware and not an emulator. I've had poor luck with the emulator, even with the hardware acceleration installed.

Any advice, or should I just hold my breath and roll with my builds requiring the integration server to be available when builds are happening?

like image 529
Argyle Avatar asked Jun 04 '13 02:06

Argyle


1 Answers

According to their Maven instructions all you need to do is add robotium-solo as a compile dependency.

repositories {
    mavenCentral()
}

dependencies {
    instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.2'
}

This will ensure you have the robotium-solo.jar file in your classpath. Then define your tests in the src/instrumentTest directory and run gradle build. See if that works?

I'll help where I can, as we converted from maven to gradle about a year ago.

*EDIT OP wanted the tests to run separately from a gradle build, so the solution is to specify a custom source set like so:

sourceSets {
    integrationTest {
        // Gives you access to the compiled classes in your tests
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
}

dependencies {
    integrationTestCompile 'com.jayway.android.robotium:robotium-solo:4.2'
}

// To run the tests: ./gradlew integrationTest
task integrationTest(type: Test) {
    testClassesDir = sourceSests.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
}

Note: I don't have the android SDK installed on this computer. If main.output does not work try it with andriod.sourceSets.main.output and see if that works.

like image 113
Joe Avatar answered Oct 12 '22 10:10

Joe