Android Test Orchestrator不适用于Android X

时间:2018-10-11 11:54:40

标签: android android-espresso android-testing androidx androidx-test

我最近将项目迁移为使用AndroidX,并使用以下文档在gradle上为我的意式浓咖啡测试配置了测试编排器:

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

我有依赖性:

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

但是,我的所有测试均未执行,并且在运行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上似乎都没有记载。

3 个答案:

答案 0 :(得分:14)

完全是出于猜测,我在gradle配置中更改了以下内容

来自:

  testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
  }

  testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
  }

似乎一切正常。

答案 1 :(得分:0)

对于其他在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)中可以正常工作。

答案 2 :(得分:-1)

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

Index()


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'}

我不得不手动修复的其余错误,但最终还是可以解决