GH-Unit for unit testing Objective-C code, why am I getting linking errors?

前端 未结 3 1353
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 02:57

I\'m trying to dive into the quite frankly terrible world of unit testing using Xcode (such a convoluted process it seems.)

Basically I have this test class, attempt

相关标签:
3条回答
  • 2021-01-19 03:15

    You have to have an @implementation for Show.

    Or you could use

    Show* s = [[objc_getClass("Show") alloc] init];
    ...
    

    or

    Show* s = [[NSClassFromString(@"Show") alloc] init];
    ...
    

    to resolving the class in run-time.

    0 讨论(0)
  • 2021-01-19 03:16

    If the target you are testing is an application, you'll need to manually include the Show.h/m files in both your main target and your test target.

    I also updated the README to reflect this:

    • If your main target is a library: Add a linked library, and select your main target; This is so you can link your test target against your main target, and then you don't have to manually include source files in both targets.
    • If your main target is an application, you will need to include these source files in the Test project manually.

    Sorry for the confusion! Having to include files in both targets is not ideal.

    0 讨论(0)
  • 2021-01-19 03:24

    Somehow Apple's example works without duplicating the .m files in the target.

    Download Apple's unit testing sample code (iPhoneUnitTests.zip) here:

    http://developer.apple.com/IPhone/library/samplecode/iPhoneUnitTests/Introduction/Intro.html

    Click on the CalcTests target. Only CalcTests.m is in this target.

    Build the target. It builds without any link errors for CalcAppDelegate or other classes.

    What's the magic that makes this work?

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