Android R.string ids 混合在多模块测试中

标签 android android-espresso android-multi-module

我的应用程序被实现为一个多模块项目(带有动态模块),其中有一个带有 espresso 测试的共享模块。这些 espresso 测试会给我不同的结果,具体取决于我是从 Android Studio 还是从命令行运行它们。
我从命令行运行测试时发现的问题是它试图针对错误的字符串资源进行断言。
实际的测试代码会断言这一点,其中 R.string.home_activity_title值为“你好”:

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

最佳答案

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

关于Android R.string ids 混合在多模块测试中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72800090/

相关文章:

java - 检查对话框是否可见 - Espresso

android.support.test.espresso.NoActivityResumedException : No activities in stage RESUMED

java - 在 JUnit 测试期间如何忽略 "Process Crashed"

带有图像和文本的 Android 布局

android - 从 Android 应用程序共享文本时如何修复错误消息 "Please use a valid Web address"?

android - Google Assistant SDK 将其集成到应用程序中

android - 一段时间后运行 TextView 选取框