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.
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.
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.
4. When you click on your Xcode project in the Navigation Area, you’ll see the newly added LogicTests under the Targets.
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.
6. Set the build/run scheme to LogicTests and either iPad or iPhone simulator.
Logic Tests do not run on the device. If you set the scheme to point to a device, you’ll get this error message:
7. With the default code written in LogicTests test class, you can try running your unit test by clicking the Product | Test menu item.
8. After running, you’ll see the result of the build with a Failed test because the template forces an STFail in the testExample.
This is how to setup Logic Testing in Xcode 4.