Beginning Automated Testing With Xcode Part 1/2

Note from Ray: This is the tenth and final iOS 6 tutorial in the iOS 6 Feast! This tutorial comes from our new book iOS 6 By Tutorials. Charlie Fulton wrote this chapter – a friend of mine and one of the newest members of the Tutorial Team. Enjoy! This is a blog post by […] By Charlie Fulton.

Leave a rating/review
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Adding a logic unit test target

You are now going to create a new test target that can be called from your build script.
In Xcode, Go to File\New\Target…\iOS\Other\Cocoa Touch Unit Testing Bundle and then click Next.

Enter GuildBrowserLogicTests for the target name, make sure that Use Automatic Reference Counting is checked, and then click Finish.

You will now have a new scheme with the same name. To test that everything is working, switch to the new scheme (using the scheme selector on the Xcode toolbar next to the Run and Stop buttons) and go to Product\Test (⌘-U).
You should see that the build succeeded, but the test failed.

As the error message indicates, this is because the unit tests have not been implemented yet. Let’s fix that!

First, delete the default test class by highlighting GuildBrowserLogicTest.h and GuildBrowserLogicTest.m, tapping Delete, and then selecting Move to Trash.

So that you don’t have to remember to switch schemes, let’s modify the main app scheme, GuildBrowser, to include your new target when running Product\Test.

Switch to the GuildBrowser scheme and then edit the scheme via Product\Edit Scheme (or you can simply Alt-click on the Run button). In the scheme editor, highlight the Test configuration, click on the + button to add a new target, select GuildBrowserLogicTests in the window and then click Add.

Your screen should look similar to this:

You are now ready to add unit test classes to this test target. You will then be able to call this target from your jenkins job.

You will do exaclty that in the next installment of this feast! Stay Thirsty.. err Hungry!

Where To Go From Here?

In a couple days, we’ll post part 2 of this tutorial. In the meantime, if you have any questions or comments, please join the forum discussion below!


This is a blog post by iOS Tutorial Team member Charlie Fulton, a full time iOS developer who enjoys hunting, fishing, and hanging out with his family.

Charlie Fulton

Contributors

Charlie Fulton

Author

Over 300 content creators. Join our team.