build.gradle:
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.4-alpha03")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0-alpha03")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.1.0-alpha06")
My androidTest class:
@get:Rule
val composeTestRule = createAndroidComposeRule(MainActivity::class.java)
@Test
fun testUI() {
composeTestRule.setContent {
AppTheme {
SomeComposeUI(
)
}
}
composeTestRule.activity.getString(R.string.apply)
InstrumentationRegistry.getInstrumentation().context.getString(R.string.apply)
}
The issue I'm having is that composeTestRule.activity.getString(R.string.apply)
or InstrumentationRegistry.getInstrumentation().context.getString(R.string.apply)
are always returning Method threw 'android.content.res.Resources$NotFoundException'
exception.
I've tried the latest alpha versions and the latest stable versions but with no luck. I've even tried the compose project which you can import in android studio and that has the same error.
Notes:
Any help would be appreciated
It turns out that with my project and the android project you can't use composeTestRule.activity.getString(R.string.apply)
whilst the debugger is attached in most scenarios.
Running without the debugger doesn't have the same issue so makes development a touch harder, but at least I have a fix.
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.