← View all posts

Migrating from OCUnit to XCTest

You might think you were in luck when Xcode offered you an option to migrate to XCTest, but shortly after trying you will discover that this isn't a true migration. Xcode will only migrate your code, it will not update your project to be testable with XCTest. There are still some steps left and unfortunately Apple have not shared any documentation on how to do this.

Note

I have later discovered that it does work as expected, but only if you run the conversion from a project directly. If you try running the conversion from a workspace you will get the problems mentioned above. I have filed this as rdar://16581037 so Apple can fix this in the future. For now, you'll need to follow the below steps.


OCUnit is deprecated, Convert to XCTest


You can follow these steps to migrate your project to XCTest once you've migrated the code with the automatic converter:

  1. Change the Wrapper Extension your project's test target in build settings from ocunit to xctest.

    Test Target's Wrapper Extension
  2. This is the scary part, you are going to need to manually edit your Xcode project by hand and replace the product type for your test target. Firstly, close Xcode and then open the project's project.pbxproj in your favourite text editor and search for the product type. You will need to change it from com.apple.product-type.bundle to com.apple.product-type.bundle.unit-test.

     productReference = 77DC06B215702EDB0001EF8C /* PalaverTests.xctest */
    -productType = "com.apple.product-type.bundle";
    +productType = "com.apple.product-type.bundle.unit-test";
    
  3. Remove the OCUnit Run Script build phase from your project's test target.

    OCUnit Run Script Build Phase
  4. Replace SenTestingKit framework with XCTest inside the test target's link with libraries build phase. Even better, you can clean up your project by enabling modules instead of adding XCTest.

    Replacing SenTestkingKit for XCTest framework
  5. For iOS, you may need to add the SDK's developer frameworks so the linker can find the XCTest framework for iOS when building the project.

    You will need to add $(SDKROOT)/Developer/Library/Frameworks to the framework search paths for the test target.

    Adding Developer frameworks to search paths

Kiwi

If you are using Kiwi, be sure switch to the XCTest pod.

pod 'Kiwi/XCTest'