How do we test resources with Compose UI Testing? ...
# compose
a
How do we test resources with Compose UI Testing? I have a valid context with:
InstrumentationRegistry.getInstrumentation().targetContext
Then calling the resulting
context
with
getString(R.string.app_name)
returns: Using
Method threw 'android.content.res.Resources$NotFoundException' exception.
It does this in my project along with the default compose template project in Android Studio. It would be handy if we had resources to test since we can then test multiple languages with UI tests and produce screenshots for this to send to our QA team as part of a release build. One project is using the latest alpha version, and the other is using the latest stable version.
a
Use
rule.activity.getString()
. If you are creating the rule using
createComposeRule()
, change it to
createAndroidComposeRule<ComponentActivity>()
.
a
Thanks Albert, I have tried that and it also throws the same error
a
It works for me and it's the "official" way:

https://youtu.be/kdwofTaEHrs?t=217

.