【发布时间】:2009-11-06 18:58:32
【问题描述】:
我正在尝试对一些实例化字体的 iphone 代码进行单元测试。我已将其范围缩小到以下崩溃单元测试:
#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).
似乎在我的单元测试目标中我没有做一些设置来完成这项工作。你如何对实例化字体的东西进行单元测试?
【问题讨论】:
-
您应该提供控制台输出以便更好地调试。但是,访问字体不需要额外的步骤,你这样做的方式就很好。问题是:不包括/链接到正确版本的 UIKit 或代码中的其他地方。
-
也遇到了这个崩溃。任何调用 systemFontOfSize: 的尝试都会完全破坏它。 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/Developer/usr/bin/otest' 异常退出,代码为 133(可能已崩溃)。
-
嘿,我能做些什么来使下面的答案更完整/有用吗?如果没有……我可以接受汉堡吗?
-
UIFont 是 UIKit 的一部分,不能在单元测试中进行测试。您可以尝试模拟对 UIFont 的调用。
-
这个问题可能无关紧要。查看stackoverflow.com/q/41404613/62 了解更多信息。
标签: iphone unit-testing xcode