• 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 unit test an object delegate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do I unit test an object delegate?


  • Subject: How do I unit test an object delegate?
  • From: Sean DeNigris <email@hidden>
  • Date: Sun, 8 Feb 2009 22:50:03 -0500

I'm unit testing a cocoa app in xcode by injecting a test bundle into the executable, so the unit tests get run at the end of every build.

Example:

@interface AppController : NSObject {
	...
	IBOutlet NSButton* startButton;
	NSSpeechSynthesizer* speechSynthesizer;
}

@implementation AppController
...
- (id)init
{
	[super init];
	speechSynthesizer = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
	[speechSynthesizer setDelegate:self];
	return self;
}

- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender didFinishSpeaking:(BOOL)success
{
[startButton setEnabled:TRUE];
}
...
@end


// Test case
- (void)testButtons
{
	STAssertTrue([startButton isEnabled], @"");

	// Start speaking
	[controller sayIt:nil];

	STAssertFalse([startButton isEnabled], @"");

	//Stop speaking
	[controller stopIt:nil];

	STAssertTrue([startButton isEnabled], @"");
}

The final assert fails because didFinishSpeaking never gets called. How do I get the delegate to be called?

- Sean


_______________________________________________

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


  • Follow-Ups:
    • Re: How do I unit test an object delegate?
      • From: Michael Ash <email@hidden>
  • Prev by Date: Re: Mixing C++ and Objective-C
  • Next by Date: Re: Drag and drop images to other application using NSFilesPromisePboardType
  • Previous by thread: Re: passing argument 1 of 'setContents:' from incompatible pointer type
  • Next by thread: Re: How do I unit test an object delegate?
  • Index(es):
    • Date
    • Thread