简体   繁体   中英

Robolectric: How to specify the locale to en-US or fr to test string formatting?

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

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

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM