Jenkins and Running AndroidJUnitRunner Instrumentation Tests

I have an Android app that I'm trying to set up with Jenkins. I have booting an emulator using the Android Emulator plugin and creating a project using a gradle script, but I cannot get it to run a simple test I wrote using AndroidJUnitRunner.

My output from Jenkins looks like this ...

+ adb shell pm list instrumentation
instrumentation:com.android.emulator.connectivity.test/android.test.InstrumentationTestRunner (target=com.android.emulator.connectivity.test)
instrumentation:com.android.emulator.gps.test/android.test.InstrumentationTestRunner (target=com.android.emulator.gps.test)
instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)
instrumentation:com.android.smoketest.tests/android.test.InstrumentationTestRunner (target=com.android.smoketest)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
[Short Sounds] $ /bin/sh -xe /tmp/hudson7415767398022941631.sh
+ adb shell am instrument -w com.sloths.speedy.shortsounds/android.support.test.runner.AndroidJUnitRunner
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.sloths.speedy.shortsounds/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.sloths.speedy.shortsounds/android.support.test.runner.AndroidJUnitRunner

      

As you can see, I have listed the adb tool using a shell command. AndroidJUnitRunner is not listed where to be found. I'm semi-positive, it needs to be there to work correctly.

I added the appropriate config tag in the build.gradle file ... ie ...

defaultConfig { 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

      

I have added these dependencies as well.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    ...
    androidTestCompile 'com.android.support.test:runner:0.2'
    // Set this dependency to use JUnit 4 rules
    androidTestCompile 'com.android.support.test:rules:0.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
}

      

And in case that's helpful, this is the test I'm trying to run. This is just a simple unit test that I would like to fail with.

import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import com.sloths.speedy.shortsounds.view.MainActivity;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class InitialFailingTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public InitialFailingTest() {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Test
    public void initialFailingTestForJenkins() {
        assertTrue(false);
    }
}

      

How can I get Jenkins to actually run my unit test? Any help is appreciated.

+3


source to share


2 answers


Try to tell jenkins to run gradle task connectedAndroidTest



+4


source


You can also follow the preparation steps for connectedAndroidTest

which

./gradlew installDebug installDebugAndroidTest

      



Then your test package and AndroidJUnitRunner should appear when you do pm list instrumentation

. It can be useful when later when you have a larger test suite and want to invoke a command am instrument

with more parameters (for example, specify the size of the test).

+4


source







All Articles