多模块测试中的Android R.String ID混合

发布于 2025-02-11 13:48:54 字数 1173 浏览 4 评论 0原文

我的应用程序被实现为一个多模块项目(带有Dynamics模块),其中有一个带有浓缩咖啡测试的共享模块。这些浓缩咖啡测试为我提供了不同的结果,具体取决于我是从Android Studio还是从命令行中运行的。

我从命令行运行测试时发现的问题是它试图对错误的字符串资源断言。

实际的测试代码正在断言此处,其中r.string.home_activity_title值是“ hello”:

assertDisplayed(R.string.home_activity_title)

但是,当它从命令行运行时,该输出的断言失败了,此输出

No views in hierarchy found matching: with string from resource id: <2131886676>[send_message_hint] value: Type a message…

通知该测试如何从命令中进行测试。线正在试图对测试中定义的另一个字符串断言。

我试图理解从AndroidStudio运行测试并从命令行运行它们之间的区别,但是我显然在这里缺少一些东西。这就是我从命令行运行测试的方式

apk="path/to/apk"
testApk="path/to/test/apk"
testRunner="my.custom.test.runner"

# Generate universal APK
echo "Generating universal APK"
sh build_develop.sh

# Install universal APK on emulator
echo "Installing universal APK"
adb uninstall <appPackage>
adb install -t $apk

echo "Building test APK"
./gradlew :testModule:assembleDebugAndroidTest

echo "Installing Test APK"
adb uninstall <testApkPackage>
adb install -t $testApk

echo "Running Acceptance Tests"
# Run all acceptance tests
adb shell am instrument -w $testRunner

My app is implemented as a multi-module project (with dynamics module), where there is a shared module with espresso tests. These espresso tests give me different outcomes depending if I run them from Android Studio or from the command line.

The issue I find when I run the tests from the command line is that it tries to assert against the wrong string resources.

The actual tests code is asserting this, where R.string.home_activity_title value is "Hello":

assertDisplayed(R.string.home_activity_title)

However when it is run from the command line, the assertion fails with this output

No views in hierarchy found matching: with string from resource id: <2131886676>[send_message_hint] value: Type a message…

Notice how the tests from the command line is trying to assert against a different string that the one is defined on the test.

I tried to understand the difference between running the tests from AndroidStudio and running them from the command line but I am clearly missing something here. This is how I run the tests from the command line

apk="path/to/apk"
testApk="path/to/test/apk"
testRunner="my.custom.test.runner"

# Generate universal APK
echo "Generating universal APK"
sh build_develop.sh

# Install universal APK on emulator
echo "Installing universal APK"
adb uninstall <appPackage>
adb install -t $apk

echo "Building test APK"
./gradlew :testModule:assembleDebugAndroidTest

echo "Installing Test APK"
adb uninstall <testApkPackage>
adb install -t $testApk

echo "Running Acceptance Tests"
# Run all acceptance tests
adb shell am instrument -w $testRunner

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2025-02-18 13:48:54

尝试指定要获得字符串的模块。
例如com.example.module.r.string.home_activity_title而不是r.string.home_activity_title

Try specifying the module for which you want the string to be obtained.
E.g. com.example.module.R.string.home_activity_title instead of R.string.home_activity_title

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文