Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins and Running AndroidJUnitRunner Instrumentation Tests

I've got an Android application which I'm trying to set up with Jenkins. I've got it booting up an emulator using the Android Emulator Plugin, and building the project with a gradle script, but I can't get it to run a simple test I wrote utilizing the 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've listed the adb instrumentation via a shell command. AndroidJUnitRunner is no where to be found in the list. I'm semi-positive it should be there to work correctly.

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

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

I've also added these dependencies.

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 its helpful here is the test I'm trying to run. It is just a simple unit test that I would like to have fail.

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 greatly appreciated.

like image 981
Sigotron Avatar asked May 02 '15 05:05

Sigotron


2 Answers

Try tell jenkins to run "gradle connectedAndroidTest" task

like image 154
WenChao Avatar answered Sep 20 '22 12:09

WenChao


You can also do the preparation steps for connectedAndroidTest which is

./gradlew installDebug installDebugAndroidTest

Then your test package and the AndroidJUnitRunner should show up when you do pm list instrumentation. Might be helpful when later on when you have a larger test suite and you want to invoke am instrument command with more options (like specifying test size).

like image 45
Yenchi Avatar answered Sep 18 '22 12:09

Yenchi