简体   繁体   中英

Android R.string ids mix in multi-module tests

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM