YH_AnalyticsTests.m 3.13 KB
//
//  YH_AnalyticsTests.m
//  YH_AnalyticsTests
//
//  Created by Tiger on 15/2/2.
//  Copyright (c) 2015年 YOHO. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "YH_Analytics.h"

@interface YH_AnalyticsTests : XCTestCase {
@private
    id mock;
}

@end

@implementation YH_AnalyticsTests

- (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 = OCMClassMock([YH_Analytics class]);
    XCTAssertNotNil(mock, @"Cannot create YH_Analytics mock");
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    mock = nil;
    [super tearDown];
    NSLog(@"%@ tearDown", self.name);
}

#pragma mark - 方法存在性验证

- (void)testStartWithAppIdMethodWithConstraint {
    NSLog(@"%@ start", self.name);   // self.name is the name of the test-case method.
    
    [[mock expect] startWithAppId:[OCMArg isKindOfClass:[NSString class]]];
    [mock startWithAppId:@"appId"];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testLogEventMethodWithConstraint {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] logEvent:[OCMArg isKindOfClass:[NSString class]] parameters:[OCMArg isKindOfClass:[NSDictionary class]]];
    [mock logEvent:@"event" parameters:@{@"key":@"value"}];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testLogErrorMethodWithConstraint {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] logError:[OCMArg isKindOfClass:[NSString class]] parameters:[OCMArg isKindOfClass:[NSDictionary class]]];
    [mock logError:@"error" parameters:@{@"key":@"value"}];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testUpdateLogStrategyCustomIntervalMethod {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] updateLogStrategy:LogStrategyCustom customInterval:1000];
    [mock updateLogStrategy:LogStrategyCustom customInterval:1000];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

#pragma mark - Test Property
- (void)testUid {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] uid];
    [mock uid];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testChannelId {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] channelId];
    [mock channelId];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testLogStrategy {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] logStrategy];
    [mock logStrategy];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testCurrentInterval {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] currentInterval];
    [mock currentInterval];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testEvent {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] event];
    [mock event];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testError {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] error];
    [mock error];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

@end