Search code examples
unit-testingxcode4

Xcode 4: Why do unit tests need their own separate scheme?


I recently downloaded and installed Mac OS X Lion on my Mac Mini. Soon thereafter I downloaded and installed Xcode 4, and have been proceeding through the tutorials. So far, so good.

Next I created a new project in Xcode 4 called 'MyApp' and selected the 'Include Unit Tests' option. I wrote my app and wrote some unit tests, all of which pass. Yay!

Incredibly, I was able to do all of this without ever once selecting the 'MyAppTests' scheme. By default, the application 'MyApp' scheme already included a 'Tests' target which correctly references the unit test files. Furthermore, the Product > Test menu (Command-U) executes those tests from within the 'MyApp' scheme. The 'MyAppTests' scheme seems completely useless. In fact, I was able to delete the 'MyAppTests' scheme entirely and nothing broke.

I am surely missing something. What is this separate 'MyAppTests' scheme used for?


Solution

  • Unit tests don't need a separate scheme, as you discovered. Xcode is initially setup to create a scheme when you create a target. Adding the unit test target added a scheme for the target.

    If you don't want Xcode to create a scheme for each new target, choose Manage Schemes from the Scheme menu in the project window toolbar. Deselect the Autocreate schemes checkbox.