iphone - UIFont 类别的单元测试用例编写问题

标签 iphone xcode ios5 xcode4 iphone-developer-program

我已向 UIFont 类添加了方法 .h 文件

  @interface UIFont (UIFont_CustomisedFont)
    +(UIFont*)bold11;
    +(UIFont*)bold12;
    +(UIFont*)bold13;

.m 文件

+(UIFont*)bold11{
  return [UIFont boldSystemFontOfSize:11];
}
+(UIFont*)bold12{
  return [UIFont boldSystemFontOfSize:12];
}
+(UIFont*)bold13{
  return [UIFont boldSystemFontOfSize:13];
}

类似的方式我已经向 UIFont 类别添加了很多方法

对于上述方法,我使用OCUnitTest编写了单元测试用例

-(void)testBold11
{
    @try {
        UILabel *lbl = [[UILabel alloc] init];
        lbl.font = [UIFont bold11];
    }    
    @catch (NSException *exception) {
        NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
        STFail(@"testBold11 failed");
    }
}

其他功能也有类似的 UnitTestCases

当我运行UnitTest时,它没有崩溃,但停在一个断点处,并且出现此消息Thread 1: EXC_BREAKPOINT(code=EXC_1385_BPT,subcode=0*0

我没有设置任何断点,并且我正在“发布”模式下运行,而不是在 Debug模式下运行。

enter image description here

请协助我解决此问题。

最佳答案

创建一个更好的测试用例,其中不涉及不相关的UILabel类:

-(void)testBold11
{
    @try {
        UIFont *font = [UIFont bold11];
        STAssertNotNil(font, @"Failed to create font");
        STAssertEquals(font.pointSize, 11.0, @"Wrong point size");
    }    
    @catch (NSException *exception) {
        NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
        STFail(@"testBold11 failed");
    }
}

关于iphone - UIFont 类别的单元测试用例编写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13562586/

相关文章:

javascript - 如何在没有互联网的情况下在 ios 中显示谷歌地图

ios - 混合方法 : Programmatically dismiss system dialogs like “<App> would like to access your contacts” in iOS

c++ - libstdc++ 和 libstdc++6 有什么区别?

iphone - 延迟 iPhone 后执行操作

uitableview - 设置 UITableView 节标题的样式

iphone - iOS 5 Twitter Framework & completionHandler block - "Capturing ' self 在这个 block 中很可能导致保留周期”

iPhone文件I/O操作及文件结构

iphone - Monotouch - 在 monotouch 项目中附加 Sqlite 数据库并部署到 iPad

ios - 图书馆?静止的?动态的?还是框架?项目在另一个项目中

ios - UITabBar 图像未在模拟器上呈现