Skip navigation.
 
mlRe: NSBundle wierdness in OCUnit target:
FROM : Chris Hanson
DATE : Tue Mar 11 21:58:22 2008

On Mar 10, 2008, at 6:57 PM, William Hunt wrote:
> On Mar 10, 2008, at 6:29 PM, Chris Hanson wrote:

>> On Mar 10, 2008, at 4:44 PM, William Hunt wrote:

>>> When I call:
>>>
>>> NSLog( @"bundlePath: %@", [[NSBundle mainBundle] bundlePath] );

>>

>>>
>>> I get:
>>>
>>> 2008-03-10 16:41:18.565 otest[3819:80f] bundlePath: /Developer/Tools

>>
>> This is expected behavior if your unit tests are being run by 
>> otest.  If you instead inject your tests into your application, 
>> then its main bundle will be returned instead (because the tests 
>> are actually run inside the application).
>>

>
> Ok, so it's the expected behavior.  Phooey!  I then have two 
> questions:
>
> 1) How do I "inject [my] tests into [my] application?"


Set the "Test Host" build setting in your test bundle target to the 
path of the executable (not just the .app wrapper) you want to inject 
your tests into.

Then tests will be run by running your application with a special 
library inserted into it, which will in turn load your test bundle and 
run its contents, instead of by running them via otest.

> 2) Can I modify the ocunit target somehow so that the Bundle is 
> where I'd expect it to be?


No, this isn't how bundles work.  +[NSBundle mainBundle] should always 
refer to the bundle for the executable that is actually running, not 
elsewhere.  If you follow the steps for #1 above you'll be fine.

I have more about this on my weblog  under "Unit Testing Cocoa 
Applications" at <http://chanson.livejournal.com/120263.html>, and in 
other posts under the "unit testing" tag.

  -- Chris

Related mailsAuthorDate
mlNSBundle wierdness in OCUnit target: William Hunt Mar 11, 00:44
mlRe: NSBundle wierdness in OCUnit target: Chris Hanson Mar 11, 02:29
mlRe: NSBundle wierdness in OCUnit target: William Hunt Mar 11, 02:57
mlRe: NSBundle wierdness in OCUnit target: Melissa J. Turner Mar 11, 04:53
mlRe: NSBundle wierdness in OCUnit target: Nir Soffer Mar 11, 05:56
mlRe: NSBundle wierdness in OCUnit target: Chris Hanson Mar 11, 21:58