How can I get a string resource in an instrumented...
# compose
b
How can I get a string resource in an instrumented test without using
createAndroidComposeRule()
? I do not want or need to load my app’s main activity. That would load all of my application content, and this is a Unit Test for a single composable. But I need to get a string resource to test with.
For now I’m doing this. It seems to work. 🤷
Copy code
val context = ApplicationProvider.getApplicationContext<Application>()
val contentDescription = context.getString(R.string.my_button_description)
composeRule.onNodeWithContentDescription(contentDescription).assertIsDisplayed()
a
Yeah, that one. Or get the context from setContent using a var
a
You can use
createAndroidComposeRule<ComponentActivity>()
. This is what
createComposeRule()
actually uses internally.
b
Thanks @Albert Chang