1

I am new to iPhone Development. I have integrated the framework GHUnitIOS to Test my application. but I haven't found documentation about how to implement Unit testing (it's my first time in Unit Testing).

Can someone can help me to begin with GHUnit, documentations, examples, explanations?

Matej
  • 9,548
  • 8
  • 49
  • 66
izan
  • 727
  • 2
  • 11
  • 22

2 Answers2

4

Here is how you configure a new target to run tests with GHUnit:

  • Download the GHUnitIOS framework. Note the name, don't download the one for OS X.

  • Add a new target to your project.

  • Add the following frameworks: GHUnitIOS.framework, CoreGraphics.framework, Foundation.framework, UIKit.framework, CoreLocation.framework

  • In Build Settings > Other Linker Flags add -ObjC and -all_load

  • Edit the ...-Info.plist for your target with a text editor and comment the following:

<!--
<key>NSMainNibFile</key>
<string>MainWindow</string>
-->
  • Add the GHUnitIOSTestMain.m file into your project.
  • In the build settings of your new target, remove the file main.m.
  • In the .pch file for your new target add #import <GHUnitIOS/GHUnit.h>

Now add a test:

// this import is already in the pch
// #import <GHUnitIOS/GHUnit.h>

@interface MyTest : GHTestCase { }
@end


@implementation MyTest

- (void)testFoo {
    // assert that foo is not nil
    GHAssertNotNULL(foo, @"foo was nil");
}

@end

Your test methods should start with test. There are other methods you can add like setUp, tearDown, setUpClass, tearDownClass, and a number of GHAssertxxx assertions.

Jano
  • 62,815
  • 21
  • 164
  • 192
0

Don't know about GHUnit, but PragPub had a nice article about TDD on the iPhone using the Google Toolbox - see http://www.pragprog.com/magazines/2010-07/tdd-on-iphone-diy

Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107