views:

68

answers:

2

I have an iPhone iOS4.1 application that uses localized strings. I have just started building unit tests using the SenTestingKit. I have been able to successfully test many different types of values.

I am unable to correctly test any of my code that uses NSLocalizedString calls, because when the code runs in my LogicTests target, all of my NSLocalizedString calls only return the string key.

I have added my Localizable.strings file to the LogicTests target.

My question is: How must I configure my LogicTests target so that calls to NSLocalizedString will return the localized string and not the string key.

A: 

Maybe NSLocalizedString will only work inside the application tests? This is a macro that invokes localizedStringForKey:value:table: on the main bundle. Maybe +[NSBundle mainBundle] returns something iffy in the testing target?

zoul
I think you are one to something, I am pretty sure the logic tests use a different bundle then the main bundle.
Jay Haase
+1  A: 
kevboh
There has to be a more graceful way to do this, but I have other stuff I need to work on. I suspect the real fix is finding a way to locate the bundle resources without weird hardcoding and introspection.
kevboh
Dude! Thanks for a such a detailed answer. This will be a big help. I am surprised so few people seem to have encountered this -- maybe not many people that localize unit test. ;-)
Jay Haase
No problem. Yeah, it's weird how I couldn't find anything on this problem in the interwebs. Definitely let me know if you figure anything else out on this.
kevboh