Unrecognized Selector SenTestCase for Category

前端 未结 4 1769
没有蜡笔的小新
没有蜡笔的小新 2020-12-20 12:50

I created a new Cocoa Touch Static Library project with Unit Testing in XCode 4 and added a category:

// NSString+Inflections.h
@interface NSString (Inflect         


        
相关标签:
4条回答
  • 2020-12-20 13:11

    I had the same situation when i was working in the Objective-c project. I did the following steps and it went well.

    1) Select the project and goto target.

    2) select Test target and add -ObjC like showing in the image.

    3) Now try to run the unit XCTest.

    0 讨论(0)
  • 2020-12-20 13:16

    I was searching for an answer this problem myself and found (I believe) a simpler solution, which doesn't require remembering to add a reference in the Compile Sources list whenever a new category class is added to the project.

    In the test target's build settings, add -ObjC to the Linking / Other Linker Flags value.

    Further explanation for why this error actually happens can be found at Apple Reference.

    0 讨论(0)
  • 2020-12-20 13:20

    Edit: Be sure to see this answer about unit test not finding files

    +1 For uploading the project. The problem is your test target does not include NSString+Inflections.m in the Build Phases.

    In XCode 4

    1. Click "Poppy" in the top of the Navigator
    2. Select "PoppyTests" under Targets
    3. Go to Build Phases
    4. Expand Compile Sources
    5. Click the + sign and then add NSString+Inflections.m

    You should then get something similar the following output

    TestSuite '/blahblah/PoppyTests.octest(Tests)' finished at 2011-03-28 21:31:34 +0000. Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.002) seconds

    0 讨论(0)
  • 2020-12-20 13:29

    I can also confirm that adding the required files to the Test project's Build Phases > Compile Sources collection solves this problem. Thanks a bunch!

    When I tried the -all_load approach, however, I started to receive a bunch of errors, like that _CGSizeZero is undefined for architecture i386. It turns out that some code - like this one, where I use CGSizeZero in one of my classes - can make the second approach break.

    Once I replaced CGSizeZero with CGSizeMake(0, 0), however, the second approach worked great as well.

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