I have written an OCUnit test, which ran fine in Xcode 3.2, and now I'm having problems with it in Xcode 4. It tests a single static function X
in class A
, which doesn't call any classes or functions (outside of library functions). The only other code that should need to be called is the static constructor, which initializes two static variables, but again, those are hardcode values (arrays) that don't call any other classes, or functions of class A
.
And yet, I had to include the .m, .mm, and .c files for all classes that it imports, and that they import, and so on, to solve the _OBJC_CLASS_$_ClassB", referenced from: errors. I don't recall having to do any of that in Xcode 3, but fine, no problem, I got it to compile. Now, I'm getting errors originating from class B
's +[B initialize]
.
Why is the static constructor getting called on a class that is not referenced in any way? How can I fix this, ideally without changing my classes to acommodate the testing?
Update
To further figure out what's going on, I commented out all my test cases and the #import "A.h"
to see what would happen. I added a single simple unit test:
- (void) testSomething {
STAssertTrue(NO, @"did it work?");
}
Still, my +[B initialize]
gets called and fails. It seems that OCUnit is crawling through all of my classes, and their +initialize
methods are getting called in the process. This makes no sense to me - how can I disable this behavior?
Here is the stack trace before my own code gets called, in case it helps:
#7 _class_initialize ()
#8 prepareForMethodLookup ()
#9 lookUpMethod ()
#10 objc_msgSend ()
#11 +[NSObject(SenTestRuntimeUtilities) senIsASuperclassOfClass:] ()
#12 +[NSObject(SenTestRuntimeUtilities) senAllSubclasses] ()
#13 +[SenTestSuite updateCache] ()
#14 +[SenTestSuite suiteForBundleCache] ()
#15 +[SenTestSuite testSuiteForBundlePath:] ()
#16 +[SenTestProbe specifiedTestSuite] ()
#17 +[SenTestProbe runTests:] ()
#18 <????> ()
#19 <????> ()
#20 <????> ()
#21 <????> ()