YH_AnalyticsTests.m 1.97 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 "OCMock.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 = [OCMockObject mockForClass:[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.
    [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 stub] startWithAppId:[OCMArg any]];
    [mock startWithAppId:[OCMArg any]];
    
    NSLog(@"%@ end", self.name);
}

- (void)testLogEventMethodWithConstraint {
    NSLog(@"%@ start", self.name);
    
    [[mock stub] logEvent:[OCMArg any] parameters:[OCMArg any]];
    [mock logEvent:@"event" parameters:nil];
    
    NSLog(@"%@ end", self.name);
}

- (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