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
found answer here how to implement application tests in xcode4?
Assuming you have an application target called "MyApp"
- Add a new target of type "other/Cocoa Unit Testing Bundle" to the project e.g "MyAppTesting". Here all Unit test files are located.
- Go to MyAppTesting Build Phases and add MyApp as Target Dependency. This assures that MyApp is build before building the MyAppTesting target.
- Open the Build Settings of MyAppTesting and change
That causes the tests to run within MyApp.
- Bundle Loader: $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp
- Test host: $(BUNDLE_LOADER)
- Open the Build Settings of MyApp and change
By doing so you do not have to include every .m-file into the test target.
- Symbols Hidden by default: NO (for both)
- Strip debug Symbols during Copy: Debug:NO