iphone - 如何使用 Xcode 4 和 OCUnit 运行应用程序测试?

标签 iphone ios xcode4 ocunit

我正在使用 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"

  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.

关于iphone - 如何使用 Xcode 4 和 OCUnit 运行应用程序测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167049/

相关文章:

iphone - ABPeoplePickerNavigationController 替代方案,允许选择多人

iphone - Xcode 4、调试、断点、NSLogs

ios - 像这样编写 Photo.app 代码

ios - UIPanGestureRecognizer 的准确起始位置?

objective-c - Xcode 创建和使用带有链接错误的静态库

ios - 关闭从 UIDocumentInteractionController 打开的 iOS 邮件应用程序会删除 iOS7 中呈现的 ViewController View

ios - UITableView 没有填满数据

ios - 从字符串 ios 获取子字符串?

xcode4 - 构建时 Xcode 4(最终版本)错误

iphone - 在 xcode 4 中将 iPhone 应用程序上传到 App Store 的步骤