XCode下的iOS单元测试
|
- (void)testSimpleFail
{
GHAssertTrue(NO, nil);
}
|
|
OCMockSampleTest.h
#import <GHUnitIOS/GHUnit.h>
@interface OCMockSampleTest : GHTestCase
@end
OCMockSampleTest.m
#import "OCMockSampleTest.h"
#import <OCMock/OCMock.h>
@implementation OCMockSampleTest
// simple test to ensure building, linking,
// and running test case works in the project
- (void)testOCMockPass
{
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:@"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
GHAssertEqualObjects(@"mocktest", returnValue,
@"Should have returned the expected string.");
}
- (void)testOCMockFail
{
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:@"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
GHAssertEqualObjects(@"thisIsTheWrongValueToCheck",
returnValue, @"Should have returned the expected string.");
}
@end
|
|
- (void)testExample
{
STFail(@"Unit tests are not implemented yet in OCUnitProjectTests");
}
|


|
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
|
|
OCMockSampleTest.h
#import <GHUnitIOS/GHUnit.h>
@interface OCMockSampleTest : GHTestCase
@end
OCMockSampleTest.m
#import "OCMockSampleTest.h"
#import <OCMock/OCMock.h>
@implementation OCMockSampleTest
// simple test to ensure building, linking,
// and running test case works in the project
- (void)testOCMockPass
{
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:@"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
GHAssertEqualObjects(@"mocktest", returnValue,
@"Should have returned the expected string.");
}
- (void)testOCMockFail
{
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:@"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
GHAssertEqualObjects(@"thisIsTheWrongValueToCheck",
returnValue, @"Should have returned the expected string.");
}
@end
|










