XCode下的iOS单元测试
作者:网络转载 发布时间:[ 2014/1/8 15:35:40 ] 推荐标签:单元测试 iOS 手机测试
3.4,删除 Tests 工程中的 UTSAppDelegate.h 和 UTSAppDelegate.m 两个文件;
3.5,修改 Tests 工程中的 main.m 为:
#import <UIKit/UIKit.h>
#import <GHUnitIOS/GHUnitIOSAppDelegate.h>
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([GHUnitIOSAppDelegate class]));
}
}
3.6,选择编译目标 Tests>iPhone 5.0 Simulator,编译运行,应该能得到如下效果。目前我们还没有编写任何实际测试,所以列表为空。

4,编写 GHUnit 测试。向 Tests 工程中添加名为 GHUnitSampleTest 的 Objective C class。其内容如下:
GHUnitSampleTest.h
#import <GHUnitIOS/GHUnit.h>
@interface GHUnitSampleTest: GHTestCase
{
}
@end
GHUnitSampleTest.m
#import "GHUnitSampleTest.h"
@implementation GHUnitSampleTest
- (void)testStrings
{
NSString *string1 = @"a string";
GHTestLog(@"I can log to the GHUnit test console: %@", string1);
// Assert string1 is not NULL, with no custom error description
GHAssertNotNULL(string1, nil);
// Assert equal objects, add custom error description
NSString *string2 = @"a string";
GHAssertEqualObjects(string1, string2, @"A custom error message. string1 should be equal to: %@.", string2);
}
@end
然后编译运行,点击 Run,效果如下:


sales@spasvo.com