...
|
...
|
@@ -17,6 +17,14 @@ |
|
|
|
|
|
#import "FakeLocationManager.h"
|
|
|
|
|
|
@interface YH_Analytics (XCTestCase)
|
|
|
|
|
|
@property (assign, nonatomic) YHLogStrategy logStrategy;
|
|
|
@property (assign, nonatomic) NSTimeInterval currentInterval;
|
|
|
@property (strong, nonatomic) CLLocationManager *locationManager;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@interface YH_AnalyticsLogicTests : XCTestCase {
|
|
|
@private
|
|
|
id assemblyAssistantMock;
|
...
|
...
|
@@ -34,7 +42,7 @@ |
|
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
|
// 开始每个测试时,恢复初始化设置
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kKeyUserDefaultsLastUploadTimestamp];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserDefaultLogStrategy];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kKeyUserDefaultsLogStrategy];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kKeyUserDefaultsCustomInterval];
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
...
|
...
|
@@ -63,7 +71,7 @@ |
|
|
+ (void)tearDown {
|
|
|
// 结束时恢复初始化设置
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kKeyUserDefaultsLastUploadTimestamp];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserDefaultLogStrategy];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kKeyUserDefaultsLogStrategy];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kKeyUserDefaultsCustomInterval];
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
...
|
...
|
@@ -88,20 +96,6 @@ |
|
|
NSLog(@"%@ end", self.name);
|
|
|
}
|
|
|
|
|
|
- (void)testStartWithAppIdMethodReceiveNotification {
|
|
|
NSLog(@"%@ start", self.name);
|
|
|
|
|
|
// NSNotificationCenter *center = [[NSNotificationCenter alloc] init];
|
|
|
// id observerMock = [OCMockObject observerMock];
|
|
|
//
|
|
|
// [center addMockObserver:observerMock name:UIApplicationWillEnterForegroundNotification object:nil];
|
|
|
// [[observerMock expect] notificationWithName:UIApplicationWillEnterForegroundNotification object:[OCMArg any]];
|
|
|
|
|
|
|
|
|
|
|
|
NSLog(@"%@ end", self.name);
|
|
|
}
|
|
|
|
|
|
- (void)testStartWithAppIdMethodWithLogStrategyAppLaunch {
|
|
|
NSLog(@"%@ start", self.name);
|
|
|
|
...
|
...
|
@@ -120,6 +114,7 @@ |
|
|
NSLog(@"%@ start", self.name);
|
|
|
|
|
|
analytics.logStrategy = LogStrategyCustom;
|
|
|
analytics.currentInterval = 100;
|
|
|
|
|
|
OCMExpect([assemblyAssistantMock uploadDiskData]);
|
|
|
|
...
|
...
|
@@ -256,6 +251,42 @@ |
|
|
NSLog(@"%@ end", self.name);
|
|
|
}
|
|
|
|
|
|
- (void)testUpdateLogStrategyMethodWithAppLaunch {
|
|
|
NSLog(@"%@ start", self.name);
|
|
|
|
|
|
[analytics updateLogStrategy:LogStrategyAppLaunch customInterval:0];
|
|
|
YHLogStrategy logStrategy = [[[NSUserDefaults standardUserDefaults] objectForKey:kKeyUserDefaultsLogStrategy] intValue];
|
|
|
NSTimeInterval interval = [[NSUserDefaults standardUserDefaults] doubleForKey:kKeyUserDefaultsCustomInterval];
|
|
|
XCTAssertEqual(logStrategy, LogStrategyAppLaunch);
|
|
|
XCTAssertEqual(interval, 0);
|
|
|
|
|
|
NSLog(@"%@ end", self.name);
|
|
|
}
|
|
|
|
|
|
- (void)testUpdateLogStrategyMethodWithImmediate{
|
|
|
NSLog(@"%@ start", self.name);
|
|
|
|
|
|
[analytics updateLogStrategy:LogStrategyImmedi customInterval:0];
|
|
|
YHLogStrategy logStrategy = [[[NSUserDefaults standardUserDefaults] objectForKey:kKeyUserDefaultsLogStrategy] intValue];
|
|
|
NSTimeInterval interval = [[NSUserDefaults standardUserDefaults] doubleForKey:kKeyUserDefaultsCustomInterval];
|
|
|
XCTAssertEqual(logStrategy, LogStrategyImmedi);
|
|
|
XCTAssertEqual(interval, 0);
|
|
|
|
|
|
NSLog(@"%@ end", self.name);
|
|
|
}
|
|
|
|
|
|
- (void)testUpdateLogStrategyMethodWithCustom {
|
|
|
NSLog(@"%@ start", self.name);
|
|
|
|
|
|
[analytics updateLogStrategy:LogStrategyCustom customInterval:100];
|
|
|
YHLogStrategy logStrategy = [[[NSUserDefaults standardUserDefaults] objectForKey:kKeyUserDefaultsLogStrategy] intValue];
|
|
|
NSTimeInterval interval = [[NSUserDefaults standardUserDefaults] doubleForKey:kKeyUserDefaultsCustomInterval];
|
|
|
XCTAssertEqual(logStrategy, LogStrategyCustom);
|
|
|
XCTAssertEqual(interval, 100);
|
|
|
|
|
|
NSLog(@"%@ end", self.name);
|
|
|
}
|
|
|
|
|
|
#pragma mark - Test Location Sevice
|
|
|
|
|
|
- (void)testLocationUpdateSuccess {
|
...
|
...
|
|