Android Test Orchestrator 无法使用 Android X

Android Test Orchestrator not working with Android X

我最近将我的项目迁移到使用 AndroidX,并使用以下文档在 gradle 上为我的 espresso 测试配置了测试协调器:

https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator

我有依赖性:

androidTestUtil 'androidx.test:orchestrator:1.1.0-beta01'

然而,none 我的测试被执行,并且当 运行 gradle 运行以下 adb shell 命令时看起来它们失败了,即:

adb shell 'CLASSPATH=$(pm path android.support.test.services) app_process / \
  android.support.test.services.shellexecutor.ShellMain am instrument -w -e \
  targetInstrumentation com.example.test/androidx.test.runner.AndroidJUnitRunner \
  android.support.test.orchestrator/.AndroidTestOrchestrator'

从上面看:似乎它正在尝试使用 android 支持版本而不是 androidx 版本来执行此命令。

androidx.

的用途似乎没有任何记载

纯属猜测,我在 gradle 配置中更改了以下内容

来自:

  testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
  }

  testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
  }

似乎一切正常。

对于遇到 Cannot convert string value 'ANDROIDX_TEST_ORCHESTRATOR' to an enum value of type 'com.android.builder.model.TestOptions$Execution' (valid case insensitive values: HOST, ANDROID_TEST_ORCHESTRATOR) 错误消息的任何其他人来说,ANDROIDX_TEST_ORCHESTRATOR 似乎与最新版本的 IntelliJ (2018.3.5) 不兼容,它在 Android Studio 中运行良好(3.3.2).

任何有复杂项目的人 - 这是我的 gradle 更改

repositories {
mavenCentral()
flatDir {
    dirs 'aars'
}
maven {
    url "https://maven.google.com"
}
google()}


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"


dependencies {
compile 'androidx.lifecycle:lifecycle-extensions:2.0.0'
compile 'androidx.core:core:1.0.0'
compile 'androidx.recyclerview:recyclerview:1.0.0'
compile 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.multidex:multidex:2.0.0'
//kapt 'androidx.databinding:databinding-compiler:1.0.0'
androidTestImplementation('androidx.test:runner:1.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation('androidx.test:rules:1.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestUtil 'androidx.test:orchestrator:1.1.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
// Espresso support
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation('androidx.test.espresso:espresso-intents:3.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation('androidx.test.espresso:espresso-web:3.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile('androidx.room:room-runtime:2.0.0', {
    exclude group: 'com.android.support'
})
kapt 'androidx.room:room-compiler:2.0.0'
compile('androidx.room:room-rxjava2:2.0.0', {
    exclude group: 'com.android.support'
})
testCompile('androidx.room:room-testing:2.0.0', {
    exclude group: 'com.google.code.gson'
})
androidTestImplementation('androidx.test.espresso:espresso-contrib:3.1.0') {
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7'
}
compile 'androidx.exifinterface:exifinterface:1.0.0'}


       classpath 'com.android.tools.build:gradle:3.4.1'

其余的错误我不得不手动修复,但最终它起作用了