Port of schuchert.wikispaces.com


iPhone.SettingUpTheEnvionment

iPhone.SettingUpTheEnvionment

UNDER CONSTRUCTION

Old Setup for XCode 3

The Video

Basic Application Setup

Note: This “works” and as I get better with XCode 4 I hope to improve this setup. If you know how to do this better, please let me know so I can learn about it and document it!

If you want to get get to it, then skip this section. These notes are for XCode 4 and GHUnit 0.4.28. Each project I set up will have a minimum of 3 projects:

Why?

GHUnit runs as an application, which means it has a main() function. Objective-C is based on C. In a C project, an executable can only have one main() when linking. The main() used for brining up the iPhone(iPad) UI is different that the main() used to execute tests. This is a deficiency in Objective-C’s execution model. So there are some obvious obvious options:

I prefer having two projects. This also provides a logical place to put the unit test source files. In languages like Java or C#, the extra source code from tests does not incur a runtime burden on the executable if they are not used. Not so with C/C++/Objective-C; that is built into the execution model. So I don’t want to link my test code into my final executable and I don’t want to hassle with more complex builds. Two projects make that an easy problem to solve.

Finally, if I have two projects, both of which have a main, it is much easier to simply put the “model” code in another project. This project will be a static library, linked by both of the first two projects.

These notes are for XCode 3.2.2. Given that Apple has messed up Unit Testing in this version, you can assume these steps are fragile. If they fail for you, please send me an email (schuchert -at- yahoo -dot- com) and let me know the version of XCode you are using. I’ll see if I can figure it out. If you’ve solved the problem, let me know and I’ll update these notes. Or, if you are feeling ambitious, I’ll give you permission to update the notes.

Setting up the three projects

Creating the Workspace

Creating the View Project

Creating the GHUnit Project

Note that by default, the project you just created is selected. If you rush though this, you’ll create the new project as a dependent of the view project.

Update the Unit Test Project

Update the Unit Test Target

Adding the Model as a Static Library

Add a first test

//
//  ItShouldHaveSmoke.m
//  Tutorial
//
//  Created by Brett Schuchert on 11/9/10.
//  Copyright 2010 Brett L. Schuchert. Use at will, just don't blame me.
//

#import <GHUnitIOS/GHUnitIOS.h>

@interface ItShouldHaveSmoke : GHTestCase {
    NSString *someVariableToInitialize;
}
@end

@implementation ItShouldHaveSmoke

-(void)setUp {
    someVariableToInitialize = @"Hello World";
}

-(void)tearDown {
    someVariableToInitialize = nil;
}

-(void)testThatItDoesHaveItsSmoke {
    GHAssertEquals(@"", someVariableToInitialize, nil);
}
@end
    GHAssertEquals(@"Hello World", someVariableToInitialize, nil);

Congratulations, you have your first test working.

Set Unit Test Executable Settings

ReviewGHUnitIOSTestMain.m. Notice that it recommends editing your unit test executable and setting the following properties:

Property Name Default Value Recommended Setting
NSDebugEnabled NO YES
NSZombieEnabled NO YES
NSDeallocateZombies NO YES
NSHangOnUncaughtException NO YES
NSEnableAutoreleasePool YES NO
NSAutoreleaseFreedObjectCheckEnabled NO YES
GHUNIT_AUTORUN NO YES

Note, the last one is one I recommend. This will make your tests run automatically.

To make create these environment settings:

Now the hard part starts.

Now Really Setting Things Up

«to be expanded»

A Few Handy Shortcut Keys

Command-r run application
Command-b quick open
F3 mapped to Edit:Find:Jump to Definition
Command-alt up-arrow Switch between .h and .m


Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.