活动构建变体没有测试工件

Active build variant does not have a test artifact

我基于 'debug' 构建变体创建了一个名为 'bitrise' 的新构建类型。使用 'debug' 构建变体时,经过检测的 androidTests 构建和 运行 很好,但是当我切换到新的 'bitrise' 构建变体时,出现以下错误:

Process finished with exit code 1
Class not found: "com.mycompany.app.ui.race.RaceFragmentUiTest"

当我 select "Edit Configurations..." -> "Android Instrumented Tests" 时出现此警告

版本

'com.android.tools.build:gradle:3.5.2'

Android Studio 3.5.2

这是来自我的 Gradle 文件的摘录

buildTypes {
    debug {
        debuggable true
        testCoverageEnabled = false
        applicationIdSuffix ".debug"
        buildConfigField("String", "BASE_ENDPOINT", BASE_ENDPOINT_DEBUG)
    }
    release {
        minifyEnabled true
        zipAlignEnabled true
        shrinkResources true
        buildConfigField("String", "BASE_ENDPOINT", BASE_ENDPOINT_PROD)
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    bitrise {
        initWith debug
        buildConfigField("String", "BASE_ENDPOINT", BASE_ENDPOINT_PROD)
    }
}

flavorDimensions "version"

productFlavors {
    mycompany {
        dimension "version"
        applicationId "com.mycompany.app"
    }
    second {
        dimension "version"
        applicationId "com.second.app"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.newrelic.agent.android:android-agent:5.24.1'
    implementation 'com.github.bumptech.glide:glide:4.3.0'
    implementation 'io.supercharge:shimmerlayout:2.0.0'
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    kapt 'androidx.lifecycle:lifecycle-common-java8:2.1.0'
    testImplementation 'org.hamcrest:hamcrest-library:1.3'
    testImplementation 'commons-logging:commons-logging:1.2'

    /**
     * Google architecture components
     */
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    testImplementation 'androidx.arch.core:core-testing:2.1.0'
    testImplementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation 'androidx.arch.core:core-testing:2.1.0'
    androidTestImplementation 'androidx.annotation:annotation:1.1.0'

    /**
     * AWS IoT
     */
    implementation 'com.amazonaws:aws-android-sdk-iot:2.15.2'
    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.15.2'
    testImplementation 'com.amazonaws:aws-android-sdk-iot:2.15.2'

    /**
     * Dagger DI dependencies
     */
    implementation 'com.google.dagger:dagger:2.24'
    kapt 'com.google.dagger:dagger-compiler:2.24'

    /**
     * Volley for network communication
     */
    implementation 'com.android.volley:volley:1.1.1'

    /**
     * Unit testing
     */
    testImplementation 'org.json:json:20190722'
    testImplementation 'org.mockito:mockito-core:3.0.0'
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
    testImplementation 'junit:junit:4.12'

    /**
     * Instrumentation testing
     */
    androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
    androidTestImplementation 'org.mockito:mockito-android:2.25.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    debugImplementation 'androidx.fragment:fragment-testing:1.2.0-rc02'

    /**
     * Json parsing
     */
    implementation 'com.squareup.moshi:moshi:1.9.2'
    kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.9.2'
}

我的单元测试 运行 在所有配置中都很好,我只有 Android Instrumented Tests

有问题

我已经尝试了这些步骤:https://developer.android.com/studio/build/build-variants#sourcesets, TestCase class not found by Android Studio, Android Studio Unit Testing: unable to find instrumentation OR class not found ex

您可以将其添加到您的 build.gradle 文件中

android {
    testBuildType "MycompanyBitrise" // or whatever build varient where you are getting 
                                       such error
}

或者只是切换到可调试 flavour/buildType。为我解决了问题:)