Question

I want to make a Robolectric test to ensure that all strings in French contains the same number of placeholders (i'm talking about %1$s) like the strings in English.

I tried to add @Config(qualifiers="fr-land") but it gives all strings in English (default) and only gives in French the strings that are not defined in English.

Also tried to create a new Resource object and to provide custom local - seems to work in Android but not in Robolectric.

Please help!

Was it helpful?

Solution

try to call following snippet at each test. this was reported as a workaround here https://github.com/robolectric/robolectric/issues/914

public static void setLocale( final Context context, final String language )
{
    final Locale locale = new Locale( language );
    Robolectric.shadowOf( context.getResources().getConfiguration() ).setLocale( locale );
    Locale.setDefault( locale );
}

OTHER TIPS

I'm using Robolectric 3.1 and nenick's solution didn't work for me, but the following solution did:

private void setLocale(Locale locale) {
    Locale.setDefault(locale);
    RuntimeEnvironment.setQualifiers(locale.getLanguage());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top