• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How do I get at my bindings in a unit test?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: How do I get at my bindings in a unit test?
      • From: Scott Ellsworth <email@hidden>
  • Prev by Date: Re: Objects as keys NSMutableDictionary
  • Next by Date: Re: How do I get at my bindings in a unit test?
  • Previous by thread: [Moderator] Re: MathML
  • Next by thread: Re: How do I get at my bindings in a unit test?
  • Index(es):
    • Date
    • Thread