YHCrashReporterTests.m
4 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// YHCrashReporterTests.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 "YHCrashReporter.h"
#import "YH_Analytics.h"
@interface YHCrashReporterTests : XCTestCase{
@private
YHCrashReporter *crashReporter;
id partialMock;
id analyticsMock;
}
@end
@implementation YHCrashReporterTests
- (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);
crashReporter = [YHCrashReporter new];
partialMock = OCMPartialMock(crashReporter);
XCTAssertNotNil(crashReporter, @"Cannot create YHCrashReporter instance");
analyticsMock = OCMClassMock([YH_Analytics class]);
OCMStub([analyticsMock sharedInstance]).andReturn(analyticsMock);
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
partialMock = nil;
crashReporter = nil;
analyticsMock = nil;
[super tearDown];
}
#pragma mark - 方法存在性验证
- (void)testCallstackAsArrayMethod {
NSLog(@"%@ start", self.name);
OCMExpect([partialMock callstackAsArray]);
[crashReporter callstackAsArray];
OCMVerifyAll(partialMock);
NSLog(@"%@ end", self.name);
}
- (void)testHandleSignalMethod {
NSLog(@"%@ start", self.name);
OCMExpect([partialMock handleSignal:[OCMArg isKindOfClass:[NSDictionary class]]]);
[crashReporter handleSignal:@{@"key" : @"value"}];
OCMVerifyAll(partialMock);
NSLog(@"%@ end", self.name);
}
- (void)testHandleNSExceptionMethod {
NSLog(@"%@ start", self.name);
OCMExpect([partialMock handleNSException:[OCMArg isKindOfClass:[NSDictionary class]]]);
[crashReporter handleNSException:@{@"key" : @"value"}];
OCMVerifyAll(partialMock);
NSLog(@"%@ end", self.name);
}
#pragma mark - 行为测试
#pragma mark -
- (void)testCallstackAsArrayMethodReturnNotNil {
NSLog(@"%@ start", self.name);
NSLog(@"%@ end", self.name);
}
#pragma mark -
- (void)testHandleSignalMethodWithInputNil {
NSLog(@"%@ start", self.name);
[[analyticsMock reject] logError:[OCMArg any] parameters:[OCMArg any]];
[crashReporter handleSignal:nil];
[analyticsMock verify];
NSLog(@"%@ end", self.name);
}
- (void)testHandleSignalMethodWithInputInvalid {
NSLog(@"%@ start", self.name);
[[analyticsMock reject] logError:[OCMArg any] parameters:[OCMArg any]];
[crashReporter handleSignal:nil];
[analyticsMock verify];
NSLog(@"%@ end", self.name);
}
- (void)testHandleSignalMethodWithInputDictionary {
NSLog(@"%@ start", self.name);
NSDictionary *userInfo = [NSDictionary dictionary];
[[analyticsMock expect] logError:@"CRASH" parameters:@{JsonKeyErrorST : userInfo}];
[crashReporter handleSignal:userInfo];
[analyticsMock verify];
NSLog(@"%@ end", self.name);
}
#pragma mark -
- (void)testHandleNSExceptionMethodWithInputNil {
NSLog(@"%@ start", self.name);
[[analyticsMock reject] logError:[OCMArg any] parameters:[OCMArg any]];
[crashReporter handleNSException:nil];
[analyticsMock verify];
NSLog(@"%@ end", self.name);
}
- (void)testHandleNSExceptionMethodWithInputInvalid {
NSLog(@"%@ start", self.name);
[[analyticsMock reject] logError:[OCMArg any] parameters:[OCMArg any]];
[crashReporter handleNSException:nil];
[analyticsMock verify];
NSLog(@"%@ end", self.name);
}
- (void)testHandleNSExceptionMethodWithInputDictionary {
NSLog(@"%@ start", self.name);
NSDictionary *userInfo = [NSDictionary dictionary];
[[analyticsMock expect] logError:@"CRASH" parameters:@{JsonKeyErrorST : userInfo}];
[crashReporter handleNSException:userInfo];
[analyticsMock verify];
NSLog(@"%@ end", self.name);
}
@end