活动的构建版本没有测试工件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了活动的构建版本没有测试工件相关的知识,希望对你有一定的参考价值。

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

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

并且当我选择“ Edit Configurations ...”->“ Android Instrumented Tests”时出现此警告Warning: Active build variant "myCompanyBitrise" does not have a test artifact.

版本

'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#sourcesetsTestCase class not found by Android StudioAndroid 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
}

以上是关于活动的构建版本没有测试工件的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 GitHub Actions 对构建工件进行版本化?

如何构建运行测试套件的 Maven 工件? “sbt 测试”如何工作?

我可以在片段中构建操作栏吗?

.Net 解决方案中的多个项目 - 结合所有项目的构建工件

Octopack 工件包括源代码

构建应用程序架构(活动和片段)的最佳方式是啥