ios单元测试工程建立
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 = [OCMockObjectmockForClass:NSString.class]; [[[mock stub] andReturn:@"mocktest"] lowercaseString]; NSString *returnValue = [mock lowercaseString]; GHAssertEqualObjects(@"mocktest", returnValue, @"Should have returned the expected string."); }
- (void)testOCMockFail {
id mock = [OCMockObjectmockForClass:NSString.class]; [[[mock stub] andReturn:@"mocktest"] lowercaseString]; NSString *returnValue = [mock lowercaseString];
GHAssertEqualObjects(@"thisIsTheWrongValueToCheck",