I want to test whether the strings are updated correctly when the user changes the language. I am using Espresso
to test whether the string matches the correct locale and I am currently changing it like so:
private fun changeLocale(language: String, country: String) {
val locale = Locale(language, country)
Locale.setDefault(locale)
val configuration = Configuration()
configuration.locale = locale
context.activity.baseContext.createConfigurationContext(configuration)
getInstrumentation().runOnMainSync {
context.activity.recreate()
}
}
The problem is that the espresso test onView(withText(expected)).check(matches(isDisplayed()))
is asserting false so I was wondering what is the correct way to set the default locale before running a test?