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,效果如下:
图中的 All 栏显示所以的测试,Failed 栏显示没有通过的测试。强大吧,GHUnit。你可以向 GHUnitSampleTest 添加新的测试,比如:
- (void)testSimpleFail
{
GHAssertTrue(NO, nil);
}