isKindOfClass and NSStringFromClass disagree about UIApplicationDelegate

前端 未结 2 1469
灰色年华
灰色年华 2020-12-15 08:25

I was playing with a simple OCUnit test for an iPhone app, and just wanted to assert that the app delegate was an instance of the class that I expected it to be. I didn\'t

相关标签:
2条回答
  • 2020-12-15 08:44

    You haven't configured your testing target correctly. If you followed this guide for unit testing applications you should have 3 targets: Calculator, CalculatorTests and CalculatorTesting. Check the 'build phases' section in CalculatorTests. In 'Compile Sources' only the SenTestCase source files should be listed there. I guess you added the CalculatorAppDelegate.m and other files there - this would lead to duplicate assemblies of the same source files which are then linked to the same application when you build the CalculatorTesting target. That explains why your assertions fail.

    EDIT: Just realized that you don't need the CalculatorTesting target in Xcode 4. Just go to Project > Edit Schemes... and make sure the unit test bundle is listed in the Test section. Then you can run unit tests with Cmd-U.

    0 讨论(0)
  • 2020-12-15 08:57

    try log out whats the return value of the operation

    NSLog(@"is it kind? %i", [appDelegate isKindOfClass:[CalculatorAppDelegate class]]);
    

    and you can even test if its a member:

    NSLog(@"is it member? %i", [appDelegate isMemberOfClass:[CalculatorAppDelegate class]]);
    

    not sure if it will help but its a starting point

    0 讨论(0)
提交回复
热议问题