问题描述
我有一个简单的单元测试的静态方法,并在模拟器中运行它们。(目标是在云中运行CI所以我正在测试模拟器。)
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.)
摇篮2.2.1仿真器的Android 5.0
Gradle 2.2.1Emulator Android 5.0
我在控制台上使用这些步骤。
I use these steps on console.
- 安卓创建AVD --force -n测试-t的android-21
- 在模拟器-avd测试 - 无 - 皮 - 无 - 音频 - 无窗和放大器;
- ADB等待换设备
- 在亚行的shell输入的keyEvent 82安培;
- 在摇篮干净installDebug
- 在摇篮connectedAndroidTest
build.gradle
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')
}
}
错误日志
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 ?
推荐答案
简短的回应:
This看来关于 java.lang.IncompatibleClassChangeError
一个很好的链接。如果你尝试在CI:
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.
您可以替换 ADB等待换装置
通过循环中,等待停止
状态(完全引导)检查亚行-e壳getprop init.svc.bootanim
作为的一样。 这里进一步信息。
You can replace adb wait-for-device
by a loop waiting for stopped
state (fully booted) checking adb -e shell getprop init.svc.bootanim
as this script in public domain does. Further info here.
可能的CI问题,双居preSSO是德precated和PSSO 2.0长者$ P $发布:
Possible CI issue, Double Espresso was deprecated and Espresso 2.0 released:
关于CI,并没有发现测试:
我回答另一个问题but具体特拉维斯-CI这里。类似的错误,但由于使用的脚本窃听。如果您运行摇篮installDebug --debug
你就会知道更多有关该错误(在这里分享日志)。
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).
但运行的CI服务器上相同的步骤,如果我是对的,你会看到一个因2分钟造成ShellCommandUnresponsiveException的InstallException INSTALL_TIMEOUT
。您可以使用环境变量 ADB_INSTALL_TIMEOUT = 6
#minutes增加此值,但是这不是你的问题了。
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 variable ADB_INSTALL_TIMEOUT=6
#minutes, but this is not your problem now.
如果您正在运行在本地第一,尝试没有 - 无窗
(所以你看到它)或添加 -no-boot-动画
(加快,但不兼容与等待的仿真器脚本),或使用 ADB等待换装置和放大器;&安培;睡300
(以确保模拟器完全启动后)。
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 use adb wait-for-device && sleep 300
(to be sure emulator is fully booted).
关于居preSSO:
双居preSSO是德precated 因为的。双居preSSO是居preSSO一个纯粹的摇篮端口1.1和杰克沃顿去precated它时,版本2.0发布两个星期前。
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.
他们更新维基和的。
和href="https://github.com/googlesamples/android-testing">发布了新的样品谷歌
And Google published new samples:
样品prerequisites:Android的SDK V21,Android编译工具v21.1.2, Android的支持库。
这些样品使用的摇篮构建系统。要建立一个项目,进入 项目目录,并使用./gradlew汇编命令或使用 导入项目,在Android的工作室。使用./gradlew connectedCheck到 运行上连接的仿真器或装置中的测试
These samples use the Gradle build system. To build a project, enter the project directory and use the ./gradlew assemble command or use "Import Project" in Android Studio. Use ./gradlew connectedCheck to run the tests on a connected emulator or device.
关于摇篮任务:
从 Android的任务和的(摇篮插件用户指南):
From Android tasks and Running tests (Gradle Plugin User Guide):
-
组装
组装项目的输出(S)的任务 -
connectedCheck
运行检查,需要连接的设备或仿真器。
assemble
The task to assemble the output(s) of the projectconnectedCheck
Runs checks that requires a connected device or emulator.
检查需要连接的设备与锚定任务名为 connectedCheck
启动。这取决于任务androidTest,因此将运行它。此任务执行以下操作:
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:
- 确保应用程序和测试应用程序内置(取决于assembleDebug和assembleTest)
- 在安装这两个应用程序
- 运行测试
- 卸载这两个应用程序。
所以我认为:
- 这是一个很好的时机,迁移到居preSSO 2.0(和避免的问题)。
- 您需要等待模拟器停止状态,并且我推荐的去了解它。
- 您不需要特定的
安装*
任务,并可以取代组装
按构建
(包括皮棉
),并使用connectedCheck
(包括connectedAndroidTest
)。 - 如果有一个以上的安装ABI,你需要选择一个(和回答no):
- 回声无| Android的创建AVD -f -n测试-t $ ANDROID_TARGET -b $ ANDROID_ABI
- 我会尝试他们的样本选择作为第二个步骤之后你的目标CI服务器上。
- It's a good moment to migrate to Espresso 2.0 (and avoid the dependencies? issue).
- You need to wait for emulator stopped state and I recommend this link to understand it.
- You don't need specific
install*
tasks and can replaceassemble
bybuild
(includeslint
) and useconnectedCheck
(includesconnectedAndroidTest
). - If there is more than one ABI installed, you'll need to choose one (and answer no):
- echo no | android create avd -f -n test -t $ANDROID_TARGET -b $ANDROID_ABI
- I would try their samples on the CI server you choose as a second step following your goal.
这篇关于在模拟器connectedAndroidTest java.lang.IncompatibleClassChangeError摇篮的JUnit居preSSO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!