How do I get at my bindings in a unit test?
How do I get at my bindings in a unit test?
- Subject: How do I get at my bindings in a unit test?
- From: Scott Ellsworth <email@hidden>
- Date: Mon, 10 Jul 2006 17:44:07 -0700
Hi, all.
I want to write a unit test that will check whether my text field is
bound to an existing object, and I am having trouble writing the test
case. Specifically, I cannot seem to get my nib loaded in a way that
would let me iterate over view objects to get their binding info.
I started with a plain old Cocoa non document based application in
Objective C. The nib is named MainMenu.nib. It has a window, named
'window', and that window has a text field as a contained object.
- (void)setUp {
NSApplication * theApplication = [NSApplication sharedApplication];
_nib = [[NSNib alloc] initWithNibNamed:@"MainMenu" bundle:nil];
NSArray * theArray;
BOOL worked = [_nib instantiateNibWithOwner:theApplication
topLevelObjects:&theArray];
STAssertTrue(worked, @"worked");
if (worked){
NSEnumerator * enumerator = [theArray objectEnumerator];
id object;
while ((object = [enumerator nextObject])) {
if ([object isKindOfClass:[NSWindow class]]){
_window = object;
}
}
}
}
- (void)tearDown {
[_nib release];
_window = nil;
}
- (void) testInfoBound
{
STAssertNotNil(_window, @"Window");
NSDictionary * bindingInfo = [_window infoForBinding:@""];
STAssertNotNil(bindingInfo, @"Binding info");
}
When run, all the asserts fail. The initWithNibNamed returns NO,
which means that the loop was never run, and so _window is nil.
Using [NSBundle mainBundle] did not change the behavior of
initWithNibNamed.
I do not want to expose the text field as an outlet, as that seems
really ugly - it pollutes other classes with information only needed
for testing.
Is there anything obviously wrong with the above?
Scott
---
email@hidden
"When a great many people are unable to find work, unemployment
results" - Calvin Coolidge, (Stanley Walker, City Editor, p. 131 (1934))
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden