1

In a test, we want to test string formatting in English and French. How to specify the locale in robolectric?

The method in this post doesn't work: Change language programmatically in Android

Community
  • 1
  • 1
Frank Du
  • 516
  • 4
  • 12

2 Answers2

4

Robolectric now includes an @Config annotation that you can put on your unit tests to specify things like this. See here for more info.

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
1

Here is what did when unit tests involve locale:

  1. Get the context from Robolectric
  2. Use the context to getString (singular/plural forms) to construct expected strings directly.
  3. Check it against the output from the methods that return strings.
Frank Du
  • 516
  • 4
  • 12