Writing XCTestCase for Mac OS Command Line Tool Writing XCTestCase for Mac OS Command Line Tool xcode xcode

Writing XCTestCase for Mac OS Command Line Tool


I'm not sure what version of Xcode you are using, but I ran into a similar problem using the templates in Xcode Version 6.2 (6C131e). That said, I was able to get XCTests to work with a Command Line Tool project. The solution was to ignore the "Target to be Tested" field during creation and instead add the Test target to the main scheme after creating it:

  1. Go to Manage Schemes. You should see your main Target’s scheme and anewly created test scheme.
  2. Select you main scheme and go to Edit.
  3. Select the Test action and add your new Test target to the testslist using the “+” in the Test action detail panel.

From there you should be able to run the tests using cmd-U.


In Xcode 8.2, I was only able to run unit tests in a command line app by adding a unit test target from the Test Navigator, then editing the testing scheme to include that new test target under the "tests" list, and manually adding testable source files to the test target from the "target membership" section of the File Inspector pane.

(Adding a unit test target from the project "add target" screen wouldn't link properly with XCTest framework, even after adding the framework to build phases.)

Following the Apple doc directions for adding a unit test target from the Test Navigator pane looks like this:

Xcode navigator pane open to Test Navigator section, after having clicked the 'add new test target or class' button

Note:

  • In the Unit Test Target setup, the "target to be tested" dropdown still won't select the command line tool. Leave this option as "None".