Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created August 1, 2009 16:18
Show Gist options
  • Save mkhl/159706 to your computer and use it in GitHub Desktop.
Save mkhl/159706 to your computer and use it in GitHub Desktop.
Cocoa UI Unit Testing
// Cocoa UI Unit Testing
// Source: http://eschatologist.net/blog/?p=205
@interface MyTestCase : SenTestCase
@end
@implementation MyTestCase
/*! Tells whether the control sends the action to the target. */
- (BOOL)checkControl:(NSControl *)control
sendsAction:(SEL)action
toTarget:(id)target
{
return ([control action] == action)
&& ([control target] == target);
}
/*! Tells whether the outlet is connected to the given destination. */
- (BOOL)checkOutlet:(id)outlet
connectsTo:(id)destination
{
return outlet == destination;
}
/*! Tells whether the object's binding is connected through the given key path. */
- (BOOL)checkObject:(id)source
hasBinding:(NSString *)binding
toObject:(id)destination
through:(NSString *)keyPath
{
NSDictionary *bindingInfo = [source infoForBinding:binding];
id observedObject = [bindingInfo objectForKey:NSObservedObjectKey];
NSString *observedKeyPath = [bindingInfo objectForKey:NSObservedKeyPathKey];
return (bindingInfo != nil)
&& (observedObject == destination)
&& [keyPath isEqualToString:observedKeyPath];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment