多模块测试中的Android R.String ID混合
我的应用程序被实现为一个多模块项目(带有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试指定要获得字符串的模块。
例如
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 ofR.string.home_activity_title