Skip to content

Instantly share code, notes, and snippets.

@torsten
Created May 15, 2012 08:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save torsten/2700140 to your computer and use it in GitHub Desktop.
Bugfix for SenTestCase when using base classes for test cases.
// OCUnit/SenTestCase's vanilla testInvocations method does not produce a unique list of methods
// when you inherit from a common test base class. Currently it will call the same test methods
// multiple times, depending on the number of base classes.
//
// To prevent these duplicate test method calls, override testInvocations like this.
//
// Written in 2012 by Torsten Becker <torsten.becker@gmail.com>
@interface BetterTestCase : SenTestCase
@end
@implementation BetterTestCase
+ (NSArray *)testInvocations
{
NSArray *invocations = [super testInvocations];
NSMutableDictionary *selectorsToInvocations = [[NSMutableDictionary alloc] init];
for (NSInvocation *invoc in invocations)
{
[selectorsToInvocations setObject:invoc forKey:[NSString stringWithUTF8String:sel_getName(invoc.selector)]];
}
return [selectorsToInvocations allValues];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment