Question in writing Unit test case for UIFont Categories

I added methods to the UIFont .h file class

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

.m file

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

Similarly, I added so many methods to the UIFont category

For the above methods, I wrote Unit test cases using 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"); } } 

Similar UnitTestCases for other functions also

When I run UnitTest , it does not crash, but stops at one breakpoint, and this message comes Thread 1: EXC_BREAKPOINT(code=EXC_1385_BPT,subcode=0*0

I did not set breakpoints, and I run the release mode, but not in debug mode.

enter image description here

please help me fix this problem.

+4
source share
2 answers

Create a better test case that does not include the irrelevant UILabel class:

 -(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"); } } 
0
source

You need to add a test host application (find the “test host” and “package loader”). Some UIKit methods fail with such a HALT condition if you do not have such a test node.

In the simplest, this is just main.m and info.plist. Please refer to my blog post explaining how to set up a minimalistic package loader to work around this issue.

0
source

All Articles