aboutsummaryrefslogtreecommitdiff
path: root/UnitTesting
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-09-18 22:00:46 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-09-18 22:00:46 +0000
commitc5d1cb4c430f0ed96355c5edf1265c57e7d5e562 (patch)
tree37902a1e248eed1d37634cb85a27852f31740030 /UnitTesting
parent43c0e6a428fedc988ddd7d71c7abbe983fa626fa (diff)
[Author: dmaclach]
Makes GTMSenTestCase work better with abstract test classes in cases where we want to tag a class as being an abstract test case even if it doesn't have any subclasses. R=thomasvl DELTA=36 (0 added, 19 deleted, 17 changed)
Diffstat (limited to 'UnitTesting')
-rw-r--r--UnitTesting/GTMSenTestCase.h18
-rw-r--r--UnitTesting/GTMSenTestCase.m23
-rw-r--r--UnitTesting/GTMUnitTestingTest.m6
3 files changed, 14 insertions, 33 deletions
diff --git a/UnitTesting/GTMSenTestCase.h b/UnitTesting/GTMSenTestCase.h
index 4f30a08..d06580f 100644
--- a/UnitTesting/GTMSenTestCase.h
+++ b/UnitTesting/GTMSenTestCase.h
@@ -1026,17 +1026,17 @@ GTM_EXTERN NSString *const SenTestLineNumberKey;
// By returning "YES" here, the tests defined by this class won't be run against
// an instance of this class. As an example class hierarchy:
//
-// FooExtensionTestCase
-// GTMTestCase <- ExtensionTestCase <
-// BarExtensionTestCase
+// FooExtensionTestCase
+// GTMTestCase <- ExtensionAbstractTestCase <
+// BarExtensionTestCase
//
// So FooExtensionTestCase and BarExtensionTestCase inherit from
-// ExtensionTestCase (and probably FooExtension and BarExtension inherit from a
-// class named Extension). We want the tests in ExtensionTestCase to be run as
-// part of FooExtensionTestCase and BarExtensionTestCase, but we don't want them
-// run against ExtensionTestCase. The default implementation of
-// isAbstractTestCase returns NO if self (being a class) has no subclasses and
-// YES otherwise.
+// ExtensionAbstractTestCase (and probably FooExtension and BarExtension inherit
+// from a class named Extension). We want the tests in ExtensionAbstractTestCase
+// to be run as part of FooExtensionTestCase and BarExtensionTestCase, but we
+// don't want them run against ExtensionAbstractTestCase. The default
+// implementation checks to see if the name of the class contains the word
+// "AbstractTest" (case sensitive).
+ (BOOL)isAbstractTestCase;
@end
diff --git a/UnitTesting/GTMSenTestCase.m b/UnitTesting/GTMSenTestCase.m
index 9d1c444..e909294 100644
--- a/UnitTesting/GTMSenTestCase.m
+++ b/UnitTesting/GTMSenTestCase.m
@@ -385,29 +385,10 @@ static int MethodSort(const void *a, const void *b) {
}
+ (BOOL)isAbstractTestCase {
- int numClasses = objc_getClassList(NULL, 0);
- BOOL isAbstract = NO;
- if (numClasses > 0) {
- size_t size = sizeof(Class) * numClasses;
- Class *classes = malloc(size);
- // This handles disposing of classes for us even if an exception should fly.
- [NSData dataWithBytesNoCopy:classes
- length:size];
- numClasses = objc_getClassList(classes, numClasses);
- for (int i = 0; i < numClasses && !isAbstract; ++i) {
- Class cls = classes[i];
- if (class_respondsToSelector(cls, @selector(superclass))) {
- Class superClass = [cls superclass];
- if ([self isEqual:superClass]) {
- isAbstract = YES;
- }
- }
- }
- }
- return isAbstract;
+ NSString *name = NSStringFromClass(self);
+ return [name rangeOfString:@"AbstractTest"].location != NSNotFound;
}
-
+ (NSArray *)testInvocations {
NSArray *invocations = nil;
if (![self isAbstractTestCase]) {
diff --git a/UnitTesting/GTMUnitTestingTest.m b/UnitTesting/GTMUnitTestingTest.m
index cd00b3e..23f3187 100644
--- a/UnitTesting/GTMUnitTestingTest.m
+++ b/UnitTesting/GTMUnitTestingTest.m
@@ -23,10 +23,10 @@
NSString *const kGTMWindowNibName = @"GTMUnitTestingTest";
NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow";
-@interface GTMAbstractUnitTestingTest : GTMTestCase
+@interface GTMUnitTestingAbstractTest : GTMTestCase
@end
-@interface GTMUnitTestingTest : GTMAbstractUnitTestingTest {
+@interface GTMUnitTestingTest : GTMUnitTestingAbstractTest {
int expectedFailureCount_;
}
@end
@@ -47,7 +47,7 @@ NSString *const kGTMWindowSaveFileName = @"GTMUnitTestingWindow";
@interface GTMUnitTestingProxyTest : NSProxy
@end
-@implementation GTMAbstractUnitTestingTest
+@implementation GTMUnitTestingAbstractTest
- (void)testAbstractUnitTest {
static int testCount = 0;
testCount += 1;