Authored by 周蓉君

去除无用target,增加单元测试工具类OCMock。Review by 阿瑟。

/*
* Copyright (c) 2009-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@class OCObserverMockObject;
@interface NSNotificationCenter(OCMAdditions)
- (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender;
@end
... ...
/*
* Copyright (c) 2009-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@interface OCMArg : NSObject
// constraining arguments
+ (id)any;
+ (SEL)anySelector;
+ (void *)anyPointer;
+ (id __autoreleasing *)anyObjectRef;
+ (id)isNil;
+ (id)isNotNil;
+ (id)isEqual:(id)value;
+ (id)isNotEqual:(id)value;
+ (id)isKindOfClass:(Class)cls;
+ (id)checkWithSelector:(SEL)selector onObject:(id)anObject;
+ (id)checkWithBlock:(BOOL (^)(id obj))block;
// manipulating arguments
+ (id *)setTo:(id)value;
+ (void *)setToValue:(NSValue *)value;
// internal use only
+ (id)resolveSpecialValues:(NSValue *)value;
@end
#define OCMOCK_ANY [OCMArg any]
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define OCMOCK_VALUE(variable) \
({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; })
#else
#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))]
#endif
... ...
/*
* Copyright (c) 2007-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@interface OCMConstraint : NSObject
+ (instancetype)constraint;
- (BOOL)evaluate:(id)value;
// if you are looking for any, isNil, etc, they have moved to OCMArg
// try to use [OCMArg checkWith...] instead of the constraintWith... methods below
+ (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject;
+ (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue;
@end
@interface OCMAnyConstraint : OCMConstraint
@end
@interface OCMIsNilConstraint : OCMConstraint
@end
@interface OCMIsNotNilConstraint : OCMConstraint
@end
@interface OCMIsNotEqualConstraint : OCMConstraint
{
@public
id testValue;
}
@end
@interface OCMInvocationConstraint : OCMConstraint
{
@public
NSInvocation *invocation;
}
@end
@interface OCMBlockConstraint : OCMConstraint
{
BOOL (^block)(id);
}
- (instancetype)initWithConstraintBlock:(BOOL (^)(id))block;
@end
#define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self]
#define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)]
... ...
/*
* Copyright (c) 2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@interface OCMLocation : NSObject
{
id testCase;
NSString *file;
NSUInteger line;
}
+ (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine;
- (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine;
- (id)testCase;
- (NSString *)file;
- (NSUInteger)line;
@end
extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line);
... ...
/*
* Copyright (c) 2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@class OCMLocation;
@class OCMRecorder;
@class OCMStubRecorder;
@class OCMockObject;
@interface OCMMacroState : NSObject
{
OCMRecorder *recorder;
}
+ (void)beginStubMacro;
+ (OCMStubRecorder *)endStubMacro;
+ (void)beginExpectMacro;
+ (OCMStubRecorder *)endExpectMacro;
+ (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation;
+ (void)endVerifyMacro;
+ (OCMMacroState *)globalState;
- (OCMRecorder *)recorder;
- (void)switchToClassMethod;
@end
... ...
/*
* Copyright (c) 2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@class OCMockObject;
@class OCMInvocationMatcher;
@interface OCMRecorder : NSProxy
{
OCMockObject *mockObject;
OCMInvocationMatcher *invocationMatcher;
}
- (instancetype)init;
- (instancetype)initWithMockObject:(OCMockObject *)aMockObject;
- (void)setMockObject:(OCMockObject *)aMockObject;
- (OCMInvocationMatcher *)invocationMatcher;
- (id)classMethod;
- (id)ignoringNonObjectArgs;
@end
... ...
/*
* Copyright (c) 2004-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import "OCMRecorder.h"
@interface OCMStubRecorder : OCMRecorder
- (id)andReturn:(id)anObject;
- (id)andReturnValue:(NSValue *)aValue;
- (id)andThrow:(NSException *)anException;
- (id)andPost:(NSNotification *)aNotification;
- (id)andCall:(SEL)selector onObject:(id)anObject;
- (id)andDo:(void (^)(NSInvocation *invocation))block;
- (id)andForwardToRealObject;
@end
@interface OCMStubRecorder (Properties)
#define andReturn(aValue) _andReturn(({ __typeof__(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(__typeof__(_v))]; }))
@property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *);
#define andThrow(anException) _andThrow(anException)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *);
#define andPost(aNotification) _andPost(aNotification)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *);
#define andCall(anObject, aSelector) _andCall(anObject, aSelector)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL);
#define andDo(aBlock) _andDo(aBlock)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *));
#define andForwardToRealObject() _andForwardToRealObject()
@property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void);
@end
... ...
/*
* Copyright (c) 2004-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
//#import <OCMock/OCMockObject.h>
//#import <OCMock/OCMRecorder.h>
//#import <OCMock/OCMStubRecorder.h>
//#import <OCMock/OCMConstraint.h>
//#import <OCMock/OCMArg.h>
//#import <OCMock/OCMLocation.h>
//#import <OCMock/OCMMacroState.h>
//#import <OCMock/NSNotificationCenter+OCMAdditions.h>
#import "OCMockObject.h"
#import "OCMRecorder.h"
#import "OCMStubRecorder.h"
#import "OCMConstraint.h"
#import "OCMArg.h"
#import "OCMLocation.h"
#import "OCMMacroState.h"
#import "NSNotificationCenter+OCMAdditions.h"
#define OCMClassMock(cls) [OCMockObject niceMockForClass:cls]
#define OCMStrictClassMock(cls) [OCMockObject mockForClass:cls]
#define OCMProtocolMock(protocol) [OCMockObject niceMockForProtocol:protocol]
#define OCMStrictProtocolMock(protocol) [OCMockObject mockForProtocol:protocol]
#define OCMPartialMock(obj) [OCMockObject partialMockForObject:obj]
#define OCMObserverMock() [OCMockObject observerMock]
#define OCMStub(invocation) \
({ \
_OCMSilenceWarnings( \
[OCMMacroState beginStubMacro]; \
invocation; \
[OCMMacroState endStubMacro]; \
); \
})
#define OCMExpect(invocation) \
({ \
_OCMSilenceWarnings( \
[OCMMacroState beginExpectMacro]; \
invocation; \
[OCMMacroState endExpectMacro]; \
); \
})
#define ClassMethod(invocation) \
_OCMSilenceWarnings( \
[[OCMMacroState globalState] switchToClassMethod]; \
invocation; \
);
#define OCMVerifyAll(mock) [mock verifyAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]
#define OCMVerifyAllWithDelay(mock, delay) [mock verifyWithDelay:delay atLocation:OCMMakeLocation(self, __FILE__, __LINE__)]
#define OCMVerify(invocation) \
({ \
_OCMSilenceWarnings( \
[OCMMacroState beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]; \
invocation; \
[OCMMacroState endVerifyMacro]; \
); \
})
#define _OCMSilenceWarnings(macro) \
({ \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wunused-value\"") \
macro \
_Pragma("clang diagnostic pop") \
})
... ...
/*
* Copyright (c) 2004-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@class OCMLocation;
@class OCMInvocationStub;
@class OCMStubRecorder;
@class OCMInvocationMatcher;
@class OCMInvocationExpectation;
@interface OCMockObject : NSProxy
{
BOOL isNice;
BOOL expectationOrderMatters;
NSMutableArray *stubs;
NSMutableArray *expectations;
NSMutableArray *exceptions;
NSMutableArray *invocations;
}
+ (id)mockForClass:(Class)aClass;
+ (id)mockForProtocol:(Protocol *)aProtocol;
+ (id)partialMockForObject:(NSObject *)anObject;
+ (id)niceMockForClass:(Class)aClass;
+ (id)niceMockForProtocol:(Protocol *)aProtocol;
+ (id)observerMock;
- (instancetype)init;
- (void)setExpectationOrderMatters:(BOOL)flag;
- (id)stub;
- (id)expect;
- (id)reject;
- (id)verify;
- (id)verifyAtLocation:(OCMLocation *)location;
- (void)verifyWithDelay:(NSTimeInterval)delay;
- (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location;
- (void)stopMocking;
// internal use only
- (void)addStub:(OCMInvocationStub *)aStub;
- (void)addExpectation:(OCMInvocationExpectation *)anExpectation;
- (BOOL)handleInvocation:(NSInvocation *)anInvocation;
- (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation;
- (BOOL)handleSelector:(SEL)sel;
- (void)verifyInvocation:(OCMInvocationMatcher *)matcher;
- (void)verifyInvocation:(OCMInvocationMatcher *)matcher atLocation:(OCMLocation *)location;
@end
... ...
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>cn.yoho.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
//
// YHAnalytics.h
// YHAnalytics
//
// Created by 王钱钧 on 15/2/6.
// Copyright (c) 2015年 YOHO. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for YHAnalytics.
FOUNDATION_EXPORT double YHAnalyticsVersionNumber;
//! Project version string for YHAnalytics.
FOUNDATION_EXPORT const unsigned char YHAnalyticsVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <YHAnalytics/PublicHeader.h>
#import <YHAnalytics/YH_Analytics.h>
#import <YHAnalytics/YHError.h>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>cn.yoho.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// YHAnalyticsTests.m
// YHAnalyticsTests
//
// Created by 王钱钧 on 15/2/6.
// Copyright (c) 2015年 YOHO. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
@interface YHAnalyticsTests : XCTestCase
@end
@implementation YHAnalyticsTests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}
@end
... ... @@ -15,6 +15,7 @@
194EDC841A7F52D100421E6C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 194EDC821A7F52D100421E6C /* LaunchScreen.xib */; };
194EDC901A7F52D100421E6C /* YH_AnalyticsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 194EDC8F1A7F52D100421E6C /* YH_AnalyticsTests.m */; };
194EDC9C1A7F555800421E6C /* YH_Analytics.m in Sources */ = {isa = PBXBuildFile; fileRef = 194EDC9B1A7F555800421E6C /* YH_Analytics.m */; };
CABC32831AD7CEB8002A4260 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CABC32821AD7CEB8002A4260 /* libOCMock.a */; };
E74D45B21ABA7C6300EFE12E /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E74D458E1ABA7C6300EFE12E /* AFHTTPRequestOperation.m */; };
E74D45B31ABA7C6300EFE12E /* AFHTTPRequestOperationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E74D45901ABA7C6300EFE12E /* AFHTTPRequestOperationManager.m */; };
E74D45B41ABA7C6300EFE12E /* AFHTTPSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E74D45921ABA7C6300EFE12E /* AFHTTPSessionManager.m */; };
... ... @@ -54,7 +55,6 @@
E7B8DE571A8343D200102CC4 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE561A8343D200102CC4 /* CoreLocation.framework */; };
E7B8DE5E1A836F8700102CC4 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */; };
E7B8DE621A838EC200102CC4 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE611A838EC200102CC4 /* AdSupport.framework */; };
E7E311C11A84C6DF004DB7DF /* YHAnalyticsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7E311C01A84C6DF004DB7DF /* YHAnalyticsTests.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
... ... @@ -65,13 +65,6 @@
remoteGlobalIDString = 194EDC6F1A7F52D100421E6C;
remoteInfo = YH_Analytics;
};
E7E311BB1A84C6DF004DB7DF /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 194EDC681A7F52D100421E6C /* Project object */;
proxyType = 1;
remoteGlobalIDString = 194EDC6F1A7F52D100421E6C;
remoteInfo = YH_Analytics;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
... ... @@ -103,6 +96,16 @@
194EDC8F1A7F52D100421E6C /* YH_AnalyticsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YH_AnalyticsTests.m; sourceTree = "<group>"; };
194EDC9A1A7F555800421E6C /* YH_Analytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_Analytics.h; sourceTree = "<group>"; };
194EDC9B1A7F555800421E6C /* YH_Analytics.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_Analytics.m; sourceTree = "<group>"; };
CABC32791AD7CE40002A4260 /* NSNotificationCenter+OCMAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNotificationCenter+OCMAdditions.h"; sourceTree = "<group>"; };
CABC327A1AD7CE40002A4260 /* OCMArg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMArg.h; sourceTree = "<group>"; };
CABC327B1AD7CE40002A4260 /* OCMConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMConstraint.h; sourceTree = "<group>"; };
CABC327C1AD7CE40002A4260 /* OCMLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMLocation.h; sourceTree = "<group>"; };
CABC327D1AD7CE40002A4260 /* OCMMacroState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMMacroState.h; sourceTree = "<group>"; };
CABC327E1AD7CE40002A4260 /* OCMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMock.h; sourceTree = "<group>"; };
CABC327F1AD7CE40002A4260 /* OCMockObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMockObject.h; sourceTree = "<group>"; };
CABC32801AD7CE40002A4260 /* OCMRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMRecorder.h; sourceTree = "<group>"; };
CABC32811AD7CE40002A4260 /* OCMStubRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMStubRecorder.h; sourceTree = "<group>"; };
CABC32821AD7CEB8002A4260 /* libOCMock.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libOCMock.a; sourceTree = "<group>"; };
E74D458D1ABA7C6300EFE12E /* AFHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFHTTPRequestOperation.h; sourceTree = "<group>"; };
E74D458E1ABA7C6300EFE12E /* AFHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPRequestOperation.m; sourceTree = "<group>"; };
E74D458F1ABA7C6300EFE12E /* AFHTTPRequestOperationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFHTTPRequestOperationManager.h; sourceTree = "<group>"; };
... ... @@ -180,11 +183,6 @@
E7B8DE5A1A83551300102CC4 /* YH_Analytics.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = YH_Analytics.entitlements; sourceTree = "<group>"; };
E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
E7B8DE611A838EC200102CC4 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
E7E311B01A84C6DF004DB7DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E7E311B11A84C6DF004DB7DF /* YHAnalytics.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YHAnalytics.h; sourceTree = "<group>"; };
E7E311B71A84C6DF004DB7DF /* YHAnalyticsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YHAnalyticsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E7E311BF1A84C6DF004DB7DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E7E311C01A84C6DF004DB7DF /* YHAnalyticsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YHAnalyticsTests.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
... ... @@ -203,13 +201,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
E7E311B41A84C6DF004DB7DF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CABC32831AD7CEB8002A4260 /* libOCMock.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ... @@ -219,11 +211,10 @@
194EDC671A7F52D100421E6C = {
isa = PBXGroup;
children = (
CABC32771AD7CDFD002A4260 /* TestDependence */,
E7B8DE631A839C7700102CC4 /* Framework */,
194EDC721A7F52D100421E6C /* YH_Analytics */,
194EDC8C1A7F52D100421E6C /* YH_AnalyticsTests */,
E7E311AE1A84C6DF004DB7DF /* YHAnalytics.Framework */,
E7E311BD1A84C6DF004DB7DF /* YHAnalyticsTests */,
194EDC711A7F52D100421E6C /* Products */,
);
sourceTree = "<group>";
... ... @@ -233,7 +224,6 @@
children = (
194EDC701A7F52D100421E6C /* YH_Analytics.app */,
194EDC891A7F52D100421E6C /* YH_AnalyticsTests.xctest */,
E7E311B71A84C6DF004DB7DF /* YHAnalyticsTests.xctest */,
);
name = Products;
sourceTree = "<group>";
... ... @@ -298,6 +288,31 @@
path = YH_Analytics;
sourceTree = "<group>";
};
CABC32771AD7CDFD002A4260 /* TestDependence */ = {
isa = PBXGroup;
children = (
CABC32781AD7CE40002A4260 /* OCMock */,
);
name = TestDependence;
sourceTree = "<group>";
};
CABC32781AD7CE40002A4260 /* OCMock */ = {
isa = PBXGroup;
children = (
CABC32821AD7CEB8002A4260 /* libOCMock.a */,
CABC32791AD7CE40002A4260 /* NSNotificationCenter+OCMAdditions.h */,
CABC327A1AD7CE40002A4260 /* OCMArg.h */,
CABC327B1AD7CE40002A4260 /* OCMConstraint.h */,
CABC327C1AD7CE40002A4260 /* OCMLocation.h */,
CABC327D1AD7CE40002A4260 /* OCMMacroState.h */,
CABC327E1AD7CE40002A4260 /* OCMock.h */,
CABC327F1AD7CE40002A4260 /* OCMockObject.h */,
CABC32801AD7CE40002A4260 /* OCMRecorder.h */,
CABC32811AD7CE40002A4260 /* OCMStubRecorder.h */,
);
path = OCMock;
sourceTree = "<group>";
};
E74D458C1ABA7C6300EFE12E /* AFNetworking */ = {
isa = PBXGroup;
children = (
... ... @@ -437,41 +452,6 @@
name = Framework;
sourceTree = "<group>";
};
E7E311AE1A84C6DF004DB7DF /* YHAnalytics.Framework */ = {
isa = PBXGroup;
children = (
E7E311B11A84C6DF004DB7DF /* YHAnalytics.h */,
E7E311AF1A84C6DF004DB7DF /* Supporting Files */,
);
name = YHAnalytics.Framework;
path = YHAnalytics;
sourceTree = "<group>";
};
E7E311AF1A84C6DF004DB7DF /* Supporting Files */ = {
isa = PBXGroup;
children = (
E7E311B01A84C6DF004DB7DF /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
E7E311BD1A84C6DF004DB7DF /* YHAnalyticsTests */ = {
isa = PBXGroup;
children = (
E7E311C01A84C6DF004DB7DF /* YHAnalyticsTests.m */,
E7E311BE1A84C6DF004DB7DF /* Supporting Files */,
);
path = YHAnalyticsTests;
sourceTree = "<group>";
};
E7E311BE1A84C6DF004DB7DF /* Supporting Files */ = {
isa = PBXGroup;
children = (
E7E311BF1A84C6DF004DB7DF /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
... ... @@ -511,24 +491,6 @@
productReference = 194EDC891A7F52D100421E6C /* YH_AnalyticsTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
E7E311B61A84C6DF004DB7DF /* YHAnalyticsTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = E7E311CC1A84C6DF004DB7DF /* Build configuration list for PBXNativeTarget "YHAnalyticsTests" */;
buildPhases = (
E7E311B31A84C6DF004DB7DF /* Sources */,
E7E311B41A84C6DF004DB7DF /* Frameworks */,
E7E311B51A84C6DF004DB7DF /* Resources */,
);
buildRules = (
);
dependencies = (
E7E311BC1A84C6DF004DB7DF /* PBXTargetDependency */,
);
name = YHAnalyticsTests;
productName = YHAnalyticsTests;
productReference = E7E311B71A84C6DF004DB7DF /* YHAnalyticsTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
... ... @@ -554,10 +516,6 @@
CreatedOnToolsVersion = 6.1.1;
TestTargetID = 194EDC6F1A7F52D100421E6C;
};
E7E311B61A84C6DF004DB7DF = {
CreatedOnToolsVersion = 6.1;
TestTargetID = 194EDC6F1A7F52D100421E6C;
};
};
};
buildConfigurationList = 194EDC6B1A7F52D100421E6C /* Build configuration list for PBXProject "YH_Analytics" */;
... ... @@ -575,7 +533,6 @@
targets = (
194EDC6F1A7F52D100421E6C /* YH_Analytics */,
194EDC881A7F52D100421E6C /* YH_AnalyticsTests */,
E7E311B61A84C6DF004DB7DF /* YHAnalyticsTests */,
);
};
/* End PBXProject section */
... ... @@ -598,13 +555,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
E7E311B51A84C6DF004DB7DF /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
... ... @@ -662,14 +612,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
E7E311B31A84C6DF004DB7DF /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E7E311C11A84C6DF004DB7DF /* YHAnalyticsTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
... ... @@ -678,11 +620,6 @@
target = 194EDC6F1A7F52D100421E6C /* YH_Analytics */;
targetProxy = 194EDC8A1A7F52D100421E6C /* PBXContainerItemProxy */;
};
E7E311BC1A84C6DF004DB7DF /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 194EDC6F1A7F52D100421E6C /* YH_Analytics */;
targetProxy = E7E311BB1A84C6DF004DB7DF /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
... ... @@ -822,8 +759,25 @@
"DEBUG=1",
"$(inherited)",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(PROJECT_DIR)/OCMock",
);
INFOPLIST_FILE = YH_AnalyticsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
/Users/bearKing/Desktop/UnitTest/OCMock,
3.1.2/iOS,
"$(PROJECT_DIR)/OCMock",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
XCTest,
"-ObjC",
);
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YH_Analytics.app/YH_Analytics";
};
... ... @@ -837,40 +791,25 @@
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = YH_AnalyticsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YH_Analytics.app/YH_Analytics";
};
name = Release;
};
E7E311C81A84C6DF004DB7DF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(PROJECT_DIR)/OCMock",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
INFOPLIST_FILE = YH_AnalyticsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
/Users/bearKing/Desktop/UnitTest/OCMock,
3.1.2/iOS,
"$(PROJECT_DIR)/OCMock",
);
INFOPLIST_FILE = YHAnalyticsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YH_Analytics.app/YH_Analytics";
};
name = Debug;
};
E7E311C91A84C6DF004DB7DF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
XCTest,
"-ObjC",
);
INFOPLIST_FILE = YHAnalyticsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YH_Analytics.app/YH_Analytics";
};
... ... @@ -906,15 +845,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E7E311CC1A84C6DF004DB7DF /* Build configuration list for PBXNativeTarget "YHAnalyticsTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E7E311C81A84C6DF004DB7DF /* Debug */,
E7E311C91A84C6DF004DB7DF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 194EDC681A7F52D100421E6C /* Project object */;
... ...
... ... @@ -143,9 +143,8 @@ static dispatch_queue_t persisitingQueue;
[YHCrashReporter sharedInstance];
}
- (void)registerAppWillEnterForegroundNotification {
- (void)registerAppWillEnterForegroundNotification
{
// 当程序切换到后台,重置session 和 eventIndex
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetSession) name:UIApplicationWillEnterForegroundNotification object:nil];
}
... ... @@ -154,6 +153,7 @@ static dispatch_queue_t persisitingQueue;
NSLog(@"app will enter foreground !!");
self.session = nil;
}
- (void)startWithAppId:(NSString *)appId
{
[self registerCrashReporter];
... ... @@ -201,7 +201,6 @@ static dispatch_queue_t persisitingQueue;
// 记录event
- (void)logEvent:(NSString *)eventId parameters:(NSDictionary *)param
{
if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.locationManager requestAlwaysAuthorization];
}
... ... @@ -222,7 +221,7 @@ static dispatch_queue_t persisitingQueue;
// 立即发送策略
if (self.logStrategy == LogStrategyImmedi) {
[[YHAssemblyAssistant shareInstance]uploadImmedilyWhithEvent:event];
[[YHAssemblyAssistant shareInstance] uploadImmedilyWhithEvent:event];
} else {
[[YHAssemblyAssistant shareInstance] saveItemData:event];
}
... ...
... ... @@ -8,8 +8,13 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "OCMock.h"
#import "YH_Analytics.h"
@interface YH_AnalyticsTests : XCTestCase
@interface YH_AnalyticsTests : XCTestCase {
@private
id mock;
}
@end
... ... @@ -18,23 +23,59 @@
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
NSLog(@"%@ setUp", self.name);
mock = [OCMockObject mockForClass:[YH_Analytics class]];
XCTAssertNotNil(mock, @"Cannot create YH_Analytics instance");
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
NSLog(@"%@ tearDown", self.name);
}
- (void)testStartWithAppIdMethodWithConstraint {
NSLog(@"%@ start", self.name); // self.name is the name of the test-case method.
[[mock stub] startWithAppId:[OCMArg any]];
[mock startWithAppId:[OCMArg any]];
NSLog(@"%@ end", self.name);
}
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
- (void)testLogEventMethodWithConstraint {
NSLog(@"%@ start", self.name);
[[mock stub] logEvent:[OCMArg any] parameters:[OCMArg any]];
[mock logEvent:@"event" parameters:nil];
NSLog(@"%@ end", self.name);
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
- (void)testLogErrorMethodWithConstraint {
NSLog(@"%@ start", self.name);
[[mock stub] logError:[OCMArg any] parameters:[OCMArg any]];
[mock logError:@"error" parameters:nil];
NSLog(@"%@ end", self.name);
}
- (void)testLogStrategy {
NSLog(@"%@ start", self.name);
[[mock stub] logStrategy];
[mock logStrategy];
NSLog(@"%@ end", self.name);
}
- (void)testSetLogStrategyWithSpecificArgument {
NSLog(@"%@ start", self.name);
[[mock stub] setLogStrategy:LogStrategyAppLaunch];
[mock setLogStrategy:LogStrategyAppLaunch];
NSLog(@"%@ end", self.name);
}
@end
... ...