Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: NSObject -poseAs:



> @implementation TestThingToTest
> - (void) testThingToTest
> {
> 	ThingToTest *thing = [[[ThingToTest alloc]init]autorelease];
> 	[[MockSingletonClass class] poseAs:[SingletonClass]];
> 	[thing methodToTest] ; // methodToTest uses the mock 
> singleton ctor
> 	// Here's where it would be nice to unposeAs.
> }
> @end

It seems to me that this is not a well-formed test case.  If you "unpose",
are you expecting that a *new* singleton is going to be created, or that the
characteristics of the singleton will stop being your mock object and go
back to the original?

In any case, I suspect (though I'm not sure) that you could add a category
in your test case that overwrites the defaultSomething message in the real
singleton class, to return your subclass.

ie,
@interface SingletonClass(TestingOnly)
+ (id)defaultSomething;		// overwrite base message handler
@end

Now make defaultSomething return an instance of your MockSingletonClass
which has appropriate gates built in, that can enable/disable itself based
on a boolean you can twiddle via some private method.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.