Load a nib file from a unit tests
Load a nib file from a unit tests
- Subject: Load a nib file from a unit tests
- From: Guillaume Cerquant <email@hidden>
- Date: Sun, 18 Jan 2009 17:41:33 +0100
Hi,
Tired of messing up with the bindings of my UI objects when tweaking
the interface, I decided to unit test them.
I'm trying to load a NIB file from a unit testing target file, so I
can check the bindings configuration of a few items.
So far I have the method below, in a subclass of SenTestCase
- (void)testPersonNameFieldHasValueBinding {
NSBundle *unitTestsBundle;
NSNib *nib;
BOOL result;
STAssertTrue(NO, @"this should never pass!"); // To make sure this
test method is executed: This test successfully fails!
unitTestsBundle = [NSBundle bundleForClass:[self class]];
STAssertNotNil(unitTestsBundle, @"nil thisBundle");
nib = [[NSNib alloc] initWithNibNamed:@"Preferences"
bundle:unitTestsBundle]; // don't forgot to add the nib to the copy
bundle resource phase of the unit tests target
STAssertNotNil (nib, @"my allocated nib is nil");
STAssertTrue(NO, @"this should never pass 0!"); // We reach this test
(and it successfully fails)
result = [nib instantiateNibWithOwner:NSApp topLevelObjects:nil]; //
we crash here
STAssertTrue (result, @"could not instantiate nib");
STAssertNotNil([[UTBindingsIBOutlets sharedManager] soundsButton],
@"nil soundsButton");
STAssertTrue(NO, @"this should never pass 2!"); // We never reach
this test
NSLog(@"If you see this log, be happy!");
}
The class UTBindingsIBOutlets is a singleton class onto which my
IBOutlets are connected.
When I run my tests, otest ends with code 139, indicating that the
code may have crashed.
And when I debug my code, it effectively crash on the line:
result = [nib instantiateNibWithOwner:NSApp topLevelObjects:nil]
I've tried many variations on this code, without success.
Any help on this will be very appreciated.
--
Guillaume Cerquant
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden