擷取 GHUnit 裡面的code....
- (NSArray *)loadAllTestCases {
NSMutableArray *testCases = [NSMutableArray array];
int count = objc_getClassList(NULL, 0);
NSMutableData *classData = [NSMutableData dataWithLength:sizeof(Class) * count];
Class *classes = (Class*)[classData mutableBytes];
NSAssert(classes, @"Couldn't allocate class list");
objc_getClassList(classes, count);
for (int i = 0; i < count; ++i) {
Class currClass = classes[i];
id testcase = nil;
if ([self isTestCaseClass:currClass]) {
testcase = [[currClass alloc] init];
} else {
continue;
}
[testCases addObject:testcase];
}
return [testCases sortedArrayUsingFunction:ClassSort context:NULL];
}
沒有留言:
張貼留言