GHUnit是一个开源的objective-c的unit test框架,他比起OCUnit来说,配置简单一些,没有Logic Tests和Application Tests的分别,但使用起来需要第三方库GHUnitIOS.framework的支持。GHUnit有GUI的界面,并非仅仅能看到log文件,比较直观,编写test case和OCUnit没有太多的区别。
言规正传,下面就来看如何使用。
platform :ios,‘6.0‘
inhibit_all_warnings!
workspace‘UnitDemo‘
xcodeproj‘UnitDemo.xcodeproj‘
#add GHUnit Framework
link_with‘GHUnitTestDemo‘
pod‘GHUnitIOS‘,‘~> 0.5.8‘
1) pod install --no-repo-update
2)pod update
在 Other Linker Flags 中增加两个 flag: -ObjC 和 -all_load。
TXLogicTest.h文件
#import "GHTestCase.h"
@interface TXLogicTest : GHTestCase
@end
TXLogicTest.m文件
#import "TXLogicTest.h"
@implementation TXLogicTest
-(void)testStringEquals2Another
{
NSString * stringA =@"stringA";
NSString * stringB =@"stringB";
GHAssertEqualObjects(stringA, stringB, @"校验2个string是否相等");
}
@end
#import <UIKit/UIKit.h>
#import "GHUnitIOS/GHUnitIOSAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
returnUIApplicationMain(argc, argv,nil,NSStringFromClass([GHUnitIOSAppDelegateclass]));
}
}
单元测试代码见:https://github.com/tingxuan/UnitDemo
利用GHUnit编写iOS单元测试,布布扣,bubuko.com
原文:http://blog.csdn.net/tingxuan_qhm/article/details/20304497