代码之家  ›  专栏  ›  技术社区  ›  FlashAsh80

Android测试编排器不与Android X一起工作

  •  7
  • FlashAsh80  · 技术社区  · 7 年前

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

    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使用什么似乎没有任何文档记录。

    2 回复  |  直到 7 年前
        1
  •  27
  •   FlashAsh80    7 年前

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

    发件人:

      testOptions {
        execution 'ANDROID_TEST_ORCHESTRATOR'
      }
    

      testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
      }
    

        2
  •  1
  •   realitydisorder    6 年前

    对于任何一个正在挣扎的人来说 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

        3
  •  -1
  •   cindy    6 年前

    有复杂项目的人吗-

    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'
    

    其余的错误我不得不手动修复,但最终还是成功了

    推荐文章