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

发布于 2024-11-10 11:20:16 字数 638 浏览 6 评论 0原文

我正在使用 OCUnit 编写单元测试,我尝试了 GHUnit 但它不适合我的情况。

我确实想运行应用程序测试,因为我的代码严重依赖于我的 ApplicationDelegate 实例。但我只能弄清楚如何运行逻辑测试而不是应用程序测试。

这是来自模板的示例测试代码,但我的测试失败(无应用程序委托)或根本没有测试代码运行。

- (void) testAppDelegate {

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

}

我找到了指南来自苹果关于如何设置测试的信息,但不适用于 Xcode 4

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老旧海报 2024-11-17 11:20:16

在这里找到答案
如何在 xcode4 中实现应用程序测试?

假设您有一个名为“MyApp”的应用程序目标

  1. 将“other/Cocoa Unit Test Bundle”类型的新目标添加到
    项目例如“MyAppTesting”。所有单元测试文件都位于此处。
  2. 转到 MyAppTesting 构建阶段并将 MyApp 添加为目标
    依赖性。这确保了 MyApp 在构建之前构建
    MyAppTesting 目标。
  3. 打开 MyAppTesting 的构建设置
    并改变

    • 捆绑加载器:$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp
    • 测试主机:$(BUNDLE_LOADER)

    这会导致测试在 MyApp 中运行。

  4. 打开MyApp的Build Settings并更改
    • 默认隐藏符号:NO(两者)
    • 复制期间删除调试符号:调试:否

    通过这样做,您不必将每个 .m 文件包含到测试目标中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文