利用GHUnit编写iOS单元测试
2014-03-02 20:44
309 查看
GHUnit是一个开源的objective-c的unit test框架,他比起OCUnit来说,配置简单一些,没有Logic Tests和Application Tests的分别,但使用起来需要第三方库GHUnitIOS.framework的支持。GHUnit有GUI的界面,并非仅仅能看到log文件,比较直观,编写test
case和OCUnit没有太多的区别。
言规正传,下面就来看如何使用。
1、创建UnitDemo的workspace文件,再创建UnitDemo的project,在项目文件根目录创建Podfile文件,通过Podfile将两者关联起来
platform :ios,'6.0'
inhibit_all_warnings!
workspace'UnitDemo'
xcodeproj'UnitDemo.xcodeproj'
2、创建Target:GHUnitTestDemo,注意选择(Empty Application)
3、添加GHUnit的framework依赖,通过cocoapods管理,通过修改Podfile文件,添加如下行
#add GHUnit Framework
link_with'GHUnitTestDemo'
pod'GHUnitIOS','~> 0.5.8'
4、下载依赖并更新
1) pod install --no-repo-update
2)pod update
5、更改Target:GHUnitTestDemo的build settings
在 Other Linker Flags 中增加两个 flag: -ObjC 和 -all_load。
6、编写测试类
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
7、修改main.m文件
#import <UIKit/UIKit.h>
#import "GHUnitIOS/GHUnitIOSAppDelegate.h"
int main(int argc,
char * argv[])
{
@autoreleasepool {
returnUIApplicationMain(argc, argv,nil,NSStringFromClass([GHUnitIOSAppDelegateclass]));
}
}
8、command+R运行,查看效果
单元测试代码见:https://github.com/tingxuan/UnitDemo
case和OCUnit没有太多的区别。
言规正传,下面就来看如何使用。
1、创建UnitDemo的workspace文件,再创建UnitDemo的project,在项目文件根目录创建Podfile文件,通过Podfile将两者关联起来
platform :ios,'6.0'
inhibit_all_warnings!
workspace'UnitDemo'
xcodeproj'UnitDemo.xcodeproj'
2、创建Target:GHUnitTestDemo,注意选择(Empty Application)
3、添加GHUnit的framework依赖,通过cocoapods管理,通过修改Podfile文件,添加如下行
#add GHUnit Framework
link_with'GHUnitTestDemo'
pod'GHUnitIOS','~> 0.5.8'
4、下载依赖并更新
1) pod install --no-repo-update
2)pod update
5、更改Target:GHUnitTestDemo的build settings
在 Other Linker Flags 中增加两个 flag: -ObjC 和 -all_load。
6、编写测试类
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
7、修改main.m文件
#import <UIKit/UIKit.h>
#import "GHUnitIOS/GHUnitIOSAppDelegate.h"
int main(int argc,
char * argv[])
{
@autoreleasepool {
returnUIApplicationMain(argc, argv,nil,NSStringFromClass([GHUnitIOSAppDelegateclass]));
}
}
8、command+R运行,查看效果
单元测试代码见:https://github.com/tingxuan/UnitDemo
相关文章推荐
- iOS单元测试GHUnit + OCMock(不使用cocoapods版)
- XCode 内置了 OCUnit 单元测试框架,但目前最好用的测试框架应该是 GHUnit。通过 GHUnit + OCMock 组合,我们可以在 iOS 下进行较强大的单元测试功能。本文将演示如何在
- ios单元测试之GHUnit
- iOS单元测试GHUnit + OCMock(使用cocoapods版)
- Xcode6下iOS单元测试——XCTest和GHUnit框架简介和比较
- Cocoapods + GHUnit + OCMock 实现iOS单元测试
- iOS开发那些事--编写OCUnit测试方法-逻辑测试方法
- iOS开发那些事--编写OCUnit测试方法-逻辑测试方法
- 利用iOS API编写简单微博客户端全过程
- iOS GHUnit输出Junitxml格式log(为后续的hudson的整合做基础)
- iOS开发 简述使用OCUnit对程序进行单元测试(UnitTest)
- iOS测试-GHUnit配置
- iOS实战演练之关于数据交互的问题(利用XAMPP搭建本地服务器, 编写PHP代码实现iOS端注册登录功能)
- iOS开发那些事--编写OCUnit测试方法-应用测试方法
- 使用 xUnit 编写 ASP.NET Core 单元测试
- iOS开发那些事--编写OCUnit测试方法-逻辑测试方法
- 利用iOS API编写简单微博客户端全过程
- iOS开发那些事--编写OCUnit测试方法-应用测试方法
- 利用J2MEUnit进行单元测试
- iOS 编程 利用UIScrollView 编写无缝循环显示图片