unittests를 실행할 때 특정 로케일을 강제 실행하는 방법이 있습니까?특정 로케일을 사용하여 unittest 실행 (ko 또는 none)
예 : 항상 en_US를 사용하거나 로케일을 강제 실행하지 않으므로 .lproj 파일이로드되지 않습니다.
내 unittest는 iOS 시뮬레이터의 설정 앱에서 현재 선택된 언어에 민감합니다. 가급적이면 언어 테스트에 대한 나의 단위 테스트를 원하지 않는 것이 좋습니다.
아래는 대답으로이를 표시 할 수 있도록 적절한 대답을 게시 문제를
@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";
체크 아웃 http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language – robinkunde
이 답변은 문제를 해결하는 방법입니다. https : // stackoverflow .com/a/19325897/211292 – ThomasW