I have a simple unit test for a static method and running them on Emulator. (Goal is to run on cloud CI so I am testing on emulator.)
Gradle 2.2.1 Emulator Android 5.0
I use these steps on console.
- android create avd --force -n test -t "android-21"
- emulator -avd test -no-skin -no-audio -no-window &
- adb wait-for-device
- adb shell input keyevent 82 &
- 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')
}
}
The error log is
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 produce this error ?
Brief response:
This seems a good link about
java.lang.IncompatibleClassChangeError
. And If you try it on CI:Emulator is not fully booted after wait-for-device, it's not ready for your tests and your app is not installed due a timeout, so there are no tests performed and the build fails as a new behavior added to alert you about it.
You can replace
adb wait-for-device
by a loop waiting forstopped
state (fully booted) checkingadb -e shell getprop init.svc.bootanim
as this script in public domain does. Further info here.Possible CI issue, Double Espresso was deprecated and Espresso 2.0 released:
About CI and no tests found:
I answered another question but specific for Travis-ci here. Similar error but due the script used was bugged. If you run
gradle installDebug --debug
you'll know more about the error (share the log here).But running the same steps on a CI server, if I'm right, you'll see an InstallException caused by ShellCommandUnresponsiveException due a two minutes
INSTALL_TIMEOUT
. You can increase this value using an environment variableADB_INSTALL_TIMEOUT=6
#minutes, but this is not your problem now.If you are running it locally first, try it without
-no-window
(so you see it) or add-no-boot-anim
(speed up it but is incompatible with wait-for-emulator script) or useadb wait-for-device && sleep 300
(to be sure emulator is fully booted).About Espresso:
Double Espresso is deprecated because Espresso 2.0 is now available. Double Espresso is a pure Gradle port of Espresso 1.1 and Jake Wharton deprecated 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 published new samples:
About Gradle tasks:
From Android tasks and Running tests (Gradle Plugin User Guide):
assemble
The task to assemble the output(s) of the projectconnectedCheck
Runs checks that requires a connected device or emulator.Checks requiring a connected device are launched with the anchor task called
connectedCheck
. This depends on the task androidTest and therefore will run it. This task does the following:So I think:
install*
tasks and can replaceassemble
bybuild
(includeslint
) and useconnectedCheck
(includesconnectedAndroidTest
).- echo no | android create avd -f -n test -t $ANDROID_TARGET -b $ANDROID_ABI