使用动态功能为Android项目创建单元和仪表测试 [英] Create Unit and Instrumentation test for Android project with dynamic features

查看:164
本文介绍了使用动态功能为Android项目创建单元和仪表测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中有主:app软件包.除此之外,该应用程序在同一软件包中包含两个动态功能::features:A和:features:B.

I have a project where I have main :app package. Besides that, the app contains of two dynamic features inside the same package, :features:A and :features:B.

这里的问题是由于以下错误,我无法运行单元和仪表测试(Espresso,UI Automator):

The issue here is that I can't run Unit and Instrumentation tests (Espresso, UI Automator) because of the following error(s):

"AAPT: error: resource string/app_name (aka com.app.A.test:string/app_name) not found." 

当我运行测试时(在这种情况下为UI测试),应用程序可以编译并正常运行.

When I run tests(UI tests in this case) App compiles and works without any issues.

我发现清单合并中会发生错误,这可以从完全错误中看出:

I figured out that error occurs on manifest merging, as it can be seen from complete error:

/Users/user/company/app/features/A/build/intermediates/tmp/manifest/androidTest/app/debug/manifestMerger7870721738992192959.xml:7:5-9:19: AAPT: error: resource string/app_name (aka com.app.A.test:string/app_name) not found.

推荐答案

一个库(上面的日志中的A或B)需要一些在测试变体的合并清单中找到的值.要解决此问题,您需要在动态功能 build.gradle 中添加测试依赖项:

A library (A or B in the logs above) is requiring some value that is found in the merged manifest from the test variant. To fix it, you need to add the test dependency in the Dynamic Feature build.gradle:

dependencies {
    implementation project(":app")
    androidTestImplementation project(":app")
}

这篇关于使用动态功能为Android项目创建单元和仪表测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆