Search code examples
iphoneiosxcode4ocunit

how to run application testing using Xcode 4 and OCUnit?


I am using OCUnit to write unit test, i tried GHUnit but it does not suit my case.

I do want to run a application test because my code heavily relied on my ApplicationDelegate instance. But i can only figure out how to run logic test but not application test.

This is a sample testing code from template, but either my test failed (no application delegate) or no testing code run at all.

- (void) testAppDelegate {

    id yourApplicationDelegate = [[UIApplication sharedApplication] delegate];
    STAssertNotNil(yourApplicationDelegate, @"UIApplication failed to find the AppDelegate");

}

I found a guide from apple about how to set up the test, but it is not for Xcode 4


Solution

  • found answer here how to implement application tests in xcode4?

    Assuming you have an application target called "MyApp"

    1. Add a new target of type "other/Cocoa Unit Testing Bundle" to the project e.g "MyAppTesting". Here all Unit test files are located.
    2. Go to MyAppTesting Build Phases and add MyApp as Target Dependency. This assures that MyApp is build before building the MyAppTesting target.
    3. Open the Build Settings of MyAppTesting and change
      • Bundle Loader: $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp
      • Test host: $(BUNDLE_LOADER)
      That causes the tests to run within MyApp.
    4. Open the Build Settings of MyApp and change
      • Symbols Hidden by default: NO (for both)
      • Strip debug Symbols during Copy: Debug:NO
      By doing so you do not have to include every .m-file into the test target.