16

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

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 的内容。

4

3 回答 3

29

纯粹通过猜测,我在我的 gradle 配置中更改了以下内容

从:

  testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
  }

  testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
  }

一切似乎都奏效了。

于 2018-10-11T11:54:39.867 回答
1

对于其他在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) 中运行良好。

于 2019-03-04T23:33:25.150 回答
-1

任何有复杂项目的人 - 这是我的 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'

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

于 2019-12-13T15:10:09.580 回答