Is there a way to force a specific locale when running unittests?
Eg. always use en_US or force no locale, so that none of the .lproj files are loaded.
My unittest is sensitive to the currently selected language in the Settings app (in the iOS Simulator). Preferably I would like my unittests not to be language sensitive.
Below is my unittest code that shows the problem
@interface MYGalleryTests : SenTestCase
@end
@implementation MYGalleryTests
-(void)test0 {
// This test doesn't work.
// I get 'No pictures' when locale is en_US
// I get 'Ingen billeder' when locale is da_DK
NSString* actual = [MYGallery emptyMessage];
NSString* expected = @"EMPTY_MESSAGE";
STAssertEqualObjects(actual, expected, nil);
}
@end
@interface MYGallery : NSObject
+(NSString*)emptyMessage;
@end
@implementation MYGallery
+(NSString*)emptyMessage {
return NSLocalizedStringFromTable(@"EMPTY_MESSAGE", @"Gallery", @"Message shown when gallery is empty");
}
@end
en.lproj/Gallery.strings
/* Message shown when gallery is empty */
"EMPTY_MESSAGE" = "No pictures";
da.lproj/Gallery.strings
/* Message shown when gallery is empty */
"EMPTY_MESSAGE" = "Ingen billeder";