我正在使用 OCUnit 编写单元测试,我尝试了 GHUnit 但它不适合我的情况。
我确实想运行应用程序测试,因为我的代码严重依赖于我的 ApplicationDelegate 实例。但我只能弄清楚如何运行逻辑测试而不是应用程序测试。
这是模板中的示例测试代码,但要么我的测试失败(没有应用程序委托(delegate)),要么根本没有运行测试代码。
- (void) testAppDelegate {
id yourApplicationDelegate = [[UIApplication sharedApplication] delegate];
STAssertNotNil(yourApplicationDelegate, @"UIApplication failed to find the AppDelegate");
}
我找到了一个 guide来自苹果关于如何设置测试,但它不适用于 Xcode 4
最佳答案
在这里找到答案 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
关于iphone - 如何使用 Xcode 4 和 OCUnit 运行应用程序测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167049/