gpt4 book ai didi

android - java.lang.NoClassDefFoundError : Test Module could not resolve classes of other Feature Module, 单元测试 - Kotlin - Android

转载 作者:行者123 更新时间:2023-12-02 12:01:50 26 4
gpt4 key购买 nike

我有以下项目结构:

Main App
--app
--featureModule1
--featureModule2
--TestKit(Library module)
其中 Testkit 具有所有依赖项,包括 app 和 featureModules。 Testkit 包括与应用程序和功能模块中的功能相关的所有单元测试。
当我从 Android Studio 运行单元测试时(右键单击-> 在 Testkit 中运行测试),它们运行良好。但是,每当我尝试从 gradle 命令运行它时: ./gradlew TestKit:testInternalDebugUnitTest , 它抛出 NoClassDefFoundError对于其他模块的所有依赖项(对于应用程序和功能模块)。
此外,我已经在测试模块中添加了所有模块的实现和 testImplementation 依赖项。
请建议:
  • 我是否需要添加在其他模块中生成的类的路径,如果是,请指导在哪里。
  • 运行覆盖率测试也失败了
    java.lang.VerifyError:错误的返回类型

  • 请建议我在这里做错了什么。
    注:
    由于 Roboelectric 在功能模块中存在多个未解决问题,我创建了一个测试套件,例如: https://github.com/robolectric/robolectric/issues/5428
    版本
    如:4.0.1
    等级:4.0.1
    毕业包装:6.5
    机器人电动车:4.3.1

    最佳答案

    我能够使用以下运行时测试依赖项解决问题:

    testRuntimeOnly(files("${projectDir}/../app/build/intermediates/app_classes/internalDebug/classes.jar"))
    testRuntimeOnly(files("${projectDir}/../featureModule1/build/intermediates/app_classes/internalDebug/classes.jar"))
    testRuntimeOnly(files("${projectDir}/../featureModule2/build/intermediates/app_classes/internalDebug/classes.jar"))
    里面 build.gradle 测试套件。
    更多详情可引用以下链接: https://github.com/android/app-bundle-samples/issues/11#issuecomment-675725610

    关于android - java.lang.NoClassDefFoundError : Test Module could not resolve classes of other Feature Module, 单元测试 - Kotlin - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63548383/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com