37

I've been using GHUnit in my project because the built in unit testing was so terrible in XCode 3.

However, now that they've been fixed in XCode 4, I want to switch back to the official testing framework.

I added a new "Cocoa Touch Unit Testing Bundle", which also adds a test case designed to fail, but "Test" under the Product menu is still grayed out.

What else do I need to do to get unit tests running in my project?

Karl
  • 14,434
  • 9
  • 44
  • 61

2 Answers2

90

You need to edit the scheme for your main application target.

  • Click the scheme selector
  • Click Edit scheme
  • Make sure the scheme you use for your actual application is selected
  • In the sidebar, you have "Build", "Run", "Test", etc. Click the "Test" entry.
  • In the table view, click the + at the bottom and select your test target, click add.

The "Test" option in the product menu is no longer grayed out.

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
  • 1
    Unfortunately, this doesn't work for me. My test target does not appear after tapping the "+" at the bottom. – Dan Loewenherz Oct 23 '14 at 02:08
  • 1
    Dan I'm having the same problem. I found a question about this, I will post if I find anything about this. http://stackoverflow.com/questions/29789839/adding-test-target-to-an-existing-project-is-not-working – teradyl May 19 '15 at 23:20
  • You need to create a new target by selecting Unittestcase bundle ad then it will be enabled I added New target and selected Unittestcase while creating new target later 'Test' enabled for the Project and then I was able to test – Ranganatha G V Jun 12 '17 at 10:47
1

You probably need to make sure that your active scheme is pointing at the right target (your test bundle).

pkananen
  • 1,325
  • 1
  • 11
  • 23
  • This fixed it for me. To set this, click the top level project entry in the left browse panel, then at the top left of the center panel, ensure the test target is selected. This should ungrey the Test entry – Joel Jul 24 '15 at 22:17