Is it possible to test the outcome of a test under a different device locale?
I'd like to test method that is using
NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
To determine the current device language. Now in my XCTest I'd like to check what happens when I'm in e.g."en-gb" instead of just "en", or simply test for a completely different language.
The NSLocalizedString
methods load the appropriate strings for the keys on launch for fast lookup, so you can't shift it around after launching. What you can do is run a test suite with one locale, then run the same test suite in a different locale.
You can set the locale for an app run in the Scheme Editor by selecting the Run action, Options tab, and picking Application Language and Application Region. Both default to the System settings, but you can change them, including using some convenient fake RTL and fake double-length languages.
(If the Test action doesn't inherit those settings for whatever reason, then there are also commandline arguments you can set to alter the defaults lookup used to order language and region preferences. This might be desirable for scripting purposes anyway.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With