How to Setup Logic Test Type of Unit Testing in Xcode 4

Apple documentation on Unit Testing Applications are about Xcode 3. I thought of posting a blog on how to do it in Xcode 4.

1. Add a new target. In Xcode, click on File | New | New Target.

Screen shot 2011-06-01 at 2.41.15 PM

2. A dialog box shows up where you can choose for a Target template. Choose Cocoa Touch Unit Testing Bundle under iOS | Other option and click the Next button.

Screen shot 2011-06-01 at 2.41.50 PM

3. In the next screen, enter the Product Name. The snapshot shows LogicTests as the Product Name because I have taken the snapshot while following the Apple documentation on how to setup LogicTests on Xcode 3. Click on Finish when you are done.

Screen shot 2011-06-01 at 2.42.02 PM

4. When you click on your Xcode project in the Navigation Area, you’ll see the newly added LogicTests under the Targets.

Screen shot 2011-06-01 at 2.42.21 PM

5. Aside from that, you’ll see a new folder with the same name as your target added to your project. The folder contains a pair of .h and .m for your first test class which inherits from SenTestCase and 3 other supporting files. This is a big improvement versus what I read in the Xcode 3 instructions. Xcode 3 instructions said that you had to do this part manually. At the bottom of your project, LogicTests.octest is also added under the Products node.

Screen shot 2011-06-01 at 2.43.04 PM

6. Set the build/run scheme to LogicTests and either iPad or iPhone simulator.

Screen shot 2011-06-01 at 2.46.41 PM


Screen shot 2011-06-01 at 2.46.15 PM

Logic Tests do not run on the device. If you set the scheme to point to a device, you’ll get this error message:

Screen shot 2011-06-01 at 2.53.01 PM

7. With the default code written in LogicTests test class, you can try running your unit test by clicking the Product | Test menu item.

Screen shot 2011-06-01 at 2.52.39 PM

8. After running, you’ll see the result of the build with a Failed test because the template forces an STFail in the testExample.

Screen shot 2011-06-01 at 2.53.32 PM

This is how to setup Logic Testing in Xcode 4.

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

One Response to How to Setup Logic Test Type of Unit Testing in Xcode 4

  1. Very useful, thankyou!

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s