Trouble with OCUnit - Instantiating custom data type
I have successfully set up unit testing for an XCode version 3.2.2 project with the iPhone SDK version 3.1.2.
I have created a class, "Callout" which I am attempting to instantiate within the context of a unit test. The class has a method,
-(id) initWithDictionary:(NSDictionary*)calloutDict includesSong:(BOOL)hasSong lastUpdate:(NSDate*)lastUpdate;
which I am calling in the unit test. When I do so, I get the error "Unrecognized instance sent to selector". This didn't make any sense to me, so out of curiosity I left everything the same and passed 'nil' in as the dictionary parameter, and it built and ran (failing the test of course, but it ran nonetheless).
Does anybody have any clue what's happening here? I don't think there is anything wrong w开发者_开发技巧ith using a custom data type in OCUnit, since I successfully did it elsewhere in the unit tests.
Here is the offending code, by the way:
- (void)testCalloutNormal
{
NSDictionary *params = [[NSDictionary alloc] initWithObjects:[NSMutableArray arrayWithObjects:@"sent",
[NSNumber numberWithInt:100],
[NSNumber numberWithInt:50],
@"challengerUsername",
@"challengedUsername",
[NSDate date],
nil]
forKeys:[NSMutableArray arrayWithObjects:@"type",
@"challengerScore",
@"challengedScore",
@"challenger",
@"challenged",
@"dateAccepted",
nil]];
Callout *callout;
callout = [[Callout alloc] initWithDictionary:params includesSong:NO lastUpdate:[NSDate date]];
NSInteger ID = 1;
callout.calloutID = 1;
[params release];
STAssertEquals(CalloutOutcomeTypeWon, callout.outcome, @"Failure: challenger's score is higher than the challengee - should return CalloutOutcomeTypeWon");
}
Thanks!
-Matt
P.S. - Most threads I have found related to OCUnit usually involve the suggestion of some supposedly better unit testing framework. I am aware that they are out there, but I'm not really interested unless you have anything different than GHUnit or the Google toolbox for Mac.
I can't say with certainty, but I doubt the problem is with OCUnit. Based on the fact that the error goes away when you pass nil for the dictionary parameter, I would guess that the offending message is sent somewhere inside your class to that dictionary reference. When the dictionary reference is nil it simply absorbs the message.
Incidentally, if you are looking for a testing framework different than OCUnit/GHUnit/GTM, I'd recommend you check out Cedar; it's BDD-style testing framework, like Rspec or Jasmine. However, as mentioned, I doubt the testing framework is your problem.
精彩评论