YHAssemblyAssistantTests.m
3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// YHAssemblyAssistantTests.m
// YH_Analytics
//
// Created by Zhou Rongjun on 15/4/15.
// Copyright (c) 2015年 YOHO. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "OCMock.h"
#import "YHAssemblyAssistant.h"
@interface YHAssemblyAssistantTests : XCTestCase {
@private
id mock;
}
@end
@implementation YHAssemblyAssistantTests
- (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:[YHAssemblyAssistant class]];
XCTAssertNotNil(mock, @"Cannot create YHAssemblyAssistant 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 - self property
- (void)testDeviceNotNil {
NSLog(@"%@ start", self.name);
YHAssemblyAssistant *assistant = [[YHAssemblyAssistant alloc] init];
YHDevice *device = [assistant device];
XCTAssertNotNil(device, @"YHAssemblyAssistant device can't be nil.");
NSLog(@"%@ end", self.name);
}
- (void)testCurrentStatusNotNil {
NSLog(@"%@ start", self.name);
YHAssemblyAssistant *assistant = [[YHAssemblyAssistant alloc] init];
YHStatus *status = [assistant currentStatus];
XCTAssertNotNil(status, @"YHAssemblyAssistant status can't be nil.");
NSLog(@"%@ end", self.name);
}
- (void)testImmediUploadItemDicNotNil {
NSLog(@"%@ start", self.name);
YHAssemblyAssistant *assistant = [[YHAssemblyAssistant alloc] init];
NSMutableDictionary *itemDic = [assistant immediUploadItemDic];
XCTAssertNotNil(itemDic, @"YHAssemblyAssistant immediUploadItemDic can't be nil.");
NSLog(@"%@ end", self.name);
}
#pragma mark - 方法存在性验证
- (void)testCanPersisitingMethod {
NSLog(@"%@ start", self.name);
[[[mock stub] andReturnValue:@YES] canPersisiting];
BOOL bPersisting = [mock canPersisiting];
XCTAssert(bPersisting, @"canPersisiting doesn't return YES.");
NSLog(@"%@ end", self.name);
}
- (void)testSaveItemDataMethodWithConstraint {
NSLog(@"%@ start", self.name);
YHAnalyItemData *data = [[YHAnalyItemData alloc] init];
[[mock stub] saveItemData:data];
[mock saveItemData:data];
NSLog(@"%@ end", self.name);
}
- (void)testGetAllEventCountMethod {
NSLog(@"%@ start", self.name);
[[[mock stub] andReturnValue:@10] getAllEventCount];
NSUInteger count = [mock getAllEventCount];
XCTAssertEqual(count, 10, @"YHAssemblyAssistant getAllEventCount doesn't return 10.");
NSLog(@"%@ end", self.name);
}
- (void)testGetUploadDataMethod {
NSLog(@"%@ start", self.name);
NSDictionary *data = @{@"key": @"value"};
[[[mock stub] andReturn:data] getUploadData];
NSDictionary *returndata = [mock getUploadData];
XCTAssertEqualObjects(data, returndata, @"YHAssemblyAssistant getUploadData doesn't return a dictionary with key:value.");
NSLog(@"%@ end", self.name);
}
- (void)testPrepareImmediUploadDicMethod {
NSLog(@"%@ start", self.name);
[[mock stub] prepareImmediUploadDic];
[mock prepareImmediUploadDic];
NSLog(@"%@ end", self.name);
}
- (void)testUpdateImmediUploadDicMethod {
NSLog(@"%@ start", self.name);
[[mock stub] updateImmediUploadDic];
[mock updateImmediUploadDic];
NSLog(@"%@ end", self.name);
}
- (void)testUploadDiskDataMethod {
NSLog(@"%@ start", self.name);
[[mock stub] uploadDiskData];
[mock uploadDiskData];
NSLog(@"%@ end", self.name);
}
- (void)testUploadImmedilyWithEventMethodWithCOnstraint {
NSLog(@"%@ start", self.name);
YHAnalyItemData *data = [[YHAnalyItemData alloc] init];
[[mock stub] uploadImmedilyWithEvent:data];
[mock uploadImmedilyWithEvent:data];
NSLog(@"%@ end", self.name);
}
@end