OS-X Cocoa Quickie #1 => Make Sure to Have Unit Tests

When starting an Xcode Cocoa Project you should have a testing project that you include. It’s a simple check box on the project creation dialogs.

Keep This Checked! Write Tests!

Keep This Checked! Write Tests!

If for some reason you inherit a project that doesn’t have unit tests, tests, or anything of the sort and need to add a testing project follow these steps. With the project open add a new target as shown below.

Add a New Target to the Project

Add a New Target to the Project

Add a Cocoa Unit Testing Bundle.

Cocoa Touch Unit Testing Bundle

Cocoa Touch Unit Testing Bundle (Click for full window and full size image)

Set the appropriate parameters for your project. Be sure to select the project from the drop down.

Set the product name and be sure to select the correct Project from the drop down. (Click for full window and full size image)

Set the product name and be sure to select the correct Project from the drop down. (Click for full window and full size image)

Once finished adding the testing target, edit the schema. The project will have an additional schema. I personally like to keep them rolled together, so delete the “*Tests” schema and just make sure that the Tests section has the right target listed.

Schema Settings

Schema Settings

If it isn’t listed, as shown in the above dialog, click the + to add the tests project. Select it in the target dialog as shown below.

Adding the test target for the schema

Adding the test target for the schema

Once all that is done then the tests can be executed from the Product -> Test menu option or the shortcut key combo of ⌘U. With the default code that is added to the target project, you’ll end up with one failing test.

Test FAIL!

Test FAIL!

Now write tests!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s