4

i'm trying to learn how i can develop on xcode 4 using tools to make unit testing. I found a lot of posts about this topic, but i can't find a tutorial wich explain how integrate those tools inside xcode 4. It seems different from xcode 3 and also the Apple example seems not working with the new xCode. Any suggestion?

Thank's

1 Answer 1

5

XCode 4 includes unit tests by default, make sure that when you create a new project, that you check the 'Include Unit Tests' option when on the screen where you choose your project name. This will create a new target called <YourProduct>Tests, ie if you called your project MarcosGame, it will create a target called MarcosGameTests. It will also create a new file group called MarcosGameTests where you should add your test files.

Whenever you create a class that you want to test, make sure you add it to your Tests target (you get this option on the screen where you give your new class a name). Then you should also add a test file to your Tests group (via the new file route, choose the Objective-C Test Case file), and make sure you include it in the MarcosGameTests target, but not the main target (MarcosGame). Stick your tests in here.

Write some tests, then when you're ready to run them, choose the 'Test' option from the Product menu, and any test failures will show up like build errors.

Sign up to request clarification or add additional context in comments.

2 Comments

You should never add application specific classes you want to test to the MarcosGameTests target. MarcosGameTests should only include test classes -- those classes that are subclassed from 'SenTestCase' -- in it, not application classes from MarcosGame. Xcode will automatically link against the MarcosGame binary and pick up all classes and dependencies. You can see this is being done if you look at the Bundle Loader entry in Build Settings for MarcosGameTests.
It should also be noted that if you are adding tests for the first time to an existing app, you will need to manually set Bundle Loader to $(BUILT_PRODUCTS_DIR)/yourAppName.app/yourAppName

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.