Gradle JUnit Espresso on Emulator connectedAndroidTest java.lang.IncompatibleClassChangeError

I have a simple unit test for a static method and running them on an emulator. (The target must be running on cloud CI, so I'm testing an emulator.)

Gradle 2.2.1 Emulator Android 5.0

I am using these steps in console.

  • android create avd -force -n test -t "android-21"
  • emulator -avd test -no-skin -no-audio -no-window &
  • adb wait-for-device
  • adb I / O tab 82 and
  • Gradle clean installDebug
  • Gradle connectedAndroidTest

build.gradle

dependencies {
    ...

    androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
        exclude group: 'com.squareup.dagger'
        exclude group: 'com.squareup.dagger:dagger:1.2.1'
    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21

        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    sourceSets {
        androidTest.setRoot('src/androidTest')
    }
}

      

Error log

Tests on test(AVD) - 5.0 failed: Instrumentation run failed due to 'java.lang.IncompatibleClassChangeError'

com.android.builder.testing.ConnectedDevice > hasTests[test(AVD) - 5.0] FAILED
No tests found.

      

What could be causing this error?

+3


source to share


1 answer


Short answer:

It seems like a good reference about java.lang.IncompatibleClassChangeError

. And if you try it in CI:

The emulator does not fully load after waiting for the device, it is not ready for your tests, and your app is not installed due to a timeout, so there are no tests and the build fails as a new behavior was added to alert you about it.

You can replace it adb wait-for-device

with a stateful stopped

(fully loaded) loop by checking adb -e shell getprop init.svc.bootanim

as this script is in the public domain. More information here .

Possible CI issue, Double Espresso has been deprecated and Espresso 2.0 has been released:

About CI and no tests found:

I have answered another question but specific for Travis-ci here . A similar error, but due to a script usage error. If you run gradle installDebug --debug

you will know more about the error (share the log here).

But running the same steps on the CI server, if I'm correct, you will see an InstallException thrown by ShellCommandUnresponsiveException in two minutes INSTALL_TIMEOUT

. This value can be increased using the ADB_INSTALL_TIMEOUT=6

#minutes environment variable, but this is not your problem now.

If you run it locally first, try it without -no-window

(this is how you see it) or add -no-boot-anim

(speed it up, but not compatible with the wait-for-emulator script) or use adb wait-for-device && sleep 300

(to make sure the emulator is fully loaded).

About espresso:

Double Espresso is deprecated because Espresso 2.0 is now available . Double Espresso is a clean port of Gradle Espresso 1.1 and Jake Wharton disapproved of it when version 2.0 was published two weeks ago.



They updated the wiki and JavaDoc (they will move it to android.com) .

You can now use the Android Support Repository to download the latest version.

And Google has posted new samples:

Sample prerequisites: Android SDK v21, Android Build Tools v21.1.2, Android Support Repository.

These samples use the Gradle build system. To create a project, enter the project directory and use the command. / gradlew build or use "Import Project" in Android Studio. Use. / gradlew connectedCheck to run tests on a connected emulator or device.

About Gradle Tasks:

From Android Task and Running Tests (Gradle Plugin User Guide):

  • assemble

    The task of assembling the project results (s)
  • connectedCheck

    Performs checks that require a connected device or emulator.

Checks that require a connected device to be connected are triggered using a bind task connectedCheck

. It depends on the androidTest task and hence starts it. This task does the following:

  • Make sure your app and test app are built (depending on Debug and assembleTest)
  • Install both apps
  • Run tests
  • Uninstall both applications.

So I think:

  • This is a good time to move to Espresso 2.0 (and avoid dependencies? ).
  • You need to wait for the emulator to stop state and I recommend this link to figure it out.
  • You don't need specific tasks install*

    and can be replaced assemble

    with build

    (includes lint

    ) and use connectedCheck

    (includes connectedAndroidTest

    ).
  • If more than one ABI is installed, you need to pick one (and answer no): - echo no | android create avd -f -n test -t $ANDROID_TARGET -b $ANDROID_ABI

  • I would try my samples on the CI server of your choice as the second step following your goal.
+9


source







All Articles