为什么在iphone单元测试中实例化UIFont会导致崩溃? [英] Why does instantiating a UIFont in an iphone unit test cause a crash?

查看:100
本文介绍了为什么在iphone单元测试中实例化UIFont会导致崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对一些实例化字体的iphone代码进行单元测试。我已将其缩小到以下崩溃单元测试:

I'm trying to unit test some iphone code that instantiates fonts. I've narrowed it down to the following crashing unit test:

#import "test.h"
#import <UIKit/UIKit.h>


@implementation test

- (void)testFonts {
  [UIFont systemFontOfSize:12];
}

@end

这会因错误而崩溃:

Test Case '-[test testFonts]' started.
/Developer/Tools/RunPlatformUnitTests.include: line 415: 79768 Trace/BPT trap          "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}"
/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/Developer/usr/bin/otest' exited abnormally with code 133 (it may have crashed).

似乎我的单元测试目标中没有做一些设置来完成这项工作。你如何对实例化字体的东西进行单元测试?

It seems like there's some setup I'm not doing in my unit test target to make this work. How do you unit test things that instantiate fonts?

推荐答案

我的一个朋友最近碰到了这个,我挖出了上一个项目我成功地设置了这个。诀窍是在应用程序测试中运行任何涉及UIFont的测试,而不是单元测试。以下是确定设置应用程序测试目标时的一些事项:

One of my friends was recently running into this, and I dug out the last project I successfully set this up on. The trick is to run any of your tests that involve UIFont in application tests, rather than unit tests. Here are a few things to make sure of when setting up your application test target:


  1. 构建阶段:将生产代码添加到测试目标中以
    为单位,包括您的主要目标作为测试目标的
    依赖项之一,而不是在测试
    目标中包含.m文件。这仅适用于组织。

  2. 构建设置:确保测试目标的Bundle Loader设置为
    $(BUILT_PRODUCTS_DIR)/您的产品名称.app /您的产品名称
    再次
    。请注意,它是 ... / Product.app/Product - 也就是说,
    在路径的最后一段中没有.app。如果您对
    感到好奇,请查看您所指的文件,找到您的构建产品,点击
    点击,选择查看包内容,然后找到可执行文件。

  3. 构建设置:您的测试目标的测试主机应设置为
    $(BUNDLE_LOADER)。简单易玩。

  4. 构建设置:测试目标的其他链接标志应包含
    -framework SenTestingKit

  5. 构建设置:构建后测试应为否。

  6. 计划:构建应包括您的测试目标和主要的
    目标,测试是两个目标中唯一选中的框。

  7. 计划:'测试'应仅包括您的测试目标。它
    包含的文件将自动添加到列表中。

  1. BUILD PHASES: Bring your production code into your test target by including your main target as one of your test target's dependencies, rather than including the .m files in your test target. This is just for organization.
  2. BUILD SETTINGS: Make sure your test target's "Bundle Loader" is set to $(BUILT_PRODUCTS_DIR)/Your Product Name.app/Your Product Name Again. Take note, it's .../Product.app/Product - that is, there is no .app in the final segment of the path. If you're curious to see the file you're referring to, find your build product, right click, select View Package Contents, then find the executable.
  3. BUILD SETTINGS: Your test target's "Test Host" should be set to $(BUNDLE_LOADER). Easy peasy.
  4. BUILD SETTINGS: The test target's Other Linker Flags should include -framework SenTestingKit.
  5. BUILD SETTINGS: "Test After Build" should be No.
  6. SCHEME: 'Build' should include both your test target, and your main target, with "test" the only box selected in both targets.
  7. SCHEME: 'Test' should include your test target only. The files it includes will automatically be added to the list.

...希望这足以获得你们都去。在一个地方并没有完全记录下来,弄清楚如何让这两种测试运行花费的时间和痛苦都比我想承认的要多。

... hopefull this'll be enough to get you all going. It's not all cleanly documented in one place, and figuring out how to get both kinds of tests running took more time and pain than I'd like to admit.

这很奇怪苹果公司似乎已经就此问题撤下了自己的doco。我想知道是否会有另一个变化......

It's strange that Apple seems to have pulled down their own doco on the matter. I wonder if there's another change coming...

如果您对上述内容有任何补充,请打我。它不是设置应用程序测试的完整指南,但以上是我遇到的无证绊脚石。 FMI,我强烈推荐这篇CocoaWithLove文章

Please hit me up if you have any additions to the above. It's not a complete guide to setting up Application testing, but the above are the undocumented stumbling blocks I ran into. FMI, I highly recommend this CocoaWithLove article.

这篇关于为什么在iphone单元测试中实例化UIFont会导致崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆