Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMPhobos
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMPhobos
Commits
07cb6ce7
Commit
07cb6ce7
authored
Apr 16, 2019
by
乔金柱
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jql/test' into 'master'
添加单元测试、修改普通埋点删除问题 See merge request
!33
parents
8a3ae2ff
098d1243
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
252 additions
and
13 deletions
+252
-13
project.pbxproj
Example/GMPhobos.xcodeproj/project.pbxproj
+0
-0
GMPhobos-Example.xcscheme
...codeproj/xcshareddata/xcschemes/GMPhobos-Example.xcscheme
+10
-2
GMPhobos_ExampleTests.m
Example/GMPhobos_ExampleTests/GMPhobos_ExampleTests.m
+37
-0
Info.plist
Example/GMPhobos_ExampleTests/Info.plist
+22
-0
Podfile.lock
Example/Podfile.lock
+3
-3
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+177
-7
Phobos.m
GMPhobos/Classes/Phobos.m
+3
-1
No files found.
Example/GMPhobos.xcodeproj/project.pbxproj
View file @
07cb6ce7
This diff is collapsed.
Click to expand it.
Example/GMPhobos.xcodeproj/xcshareddata/xcschemes/GMPhobos-Example.xcscheme
View file @
07cb6ce7
...
...
@@ -26,7 +26,6 @@
buildConfiguration =
"Debug"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
language =
""
shouldUseLaunchSchemeArgsEnv =
"YES"
>
<Testables>
<TestableReference
...
...
@@ -44,6 +43,16 @@
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
skipped =
"NO"
>
<BuildableReference
BuildableIdentifier =
"primary"
BlueprintIdentifier =
"63EFAB0D22658352005EEAC6"
BuildableName =
"GMPhobos_ExampleTests.xctest"
BlueprintName =
"GMPhobos_ExampleTests"
ReferencedContainer =
"container:GMPhobos.xcodeproj"
>
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
...
...
@@ -61,7 +70,6 @@
buildConfiguration =
"Debug"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
language =
""
launchStyle =
"0"
useCustomWorkingDirectory =
"NO"
ignoresPersistentStateOnLaunch =
"NO"
...
...
Example/GMPhobos_ExampleTests/GMPhobos_ExampleTests.m
0 → 100644
View file @
07cb6ce7
//
// GMPhobos_ExampleTests.m
// GMPhobos_ExampleTests
//
// Created by Jing on 2019/4/16.
// Copyright © 2019 licong. All rights reserved.
//
#import <XCTest/XCTest.h>
@interface
GMPhobos_ExampleTests
:
XCTestCase
@end
@implementation
GMPhobos_ExampleTests
-
(
void
)
setUp
{
// Put setup code here. This method is called before the invocation of each test method in the class.
}
-
(
void
)
tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
-
(
void
)
testExample
{
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
-
(
void
)
testPerformanceExample
{
// This is an example of a performance test case.
[
self
measureBlock
:
^
{
// Put the code you want to measure the time of here.
}];
}
@end
Example/GMPhobos_ExampleTests/Info.plist
0 → 100644
View file @
07cb6ce7
<
?xml
v
e
rsion="
1
.
0
"
e
n
c
o
d
ing="UT
F
-
8
"?
>
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
$
(
DEVELOPMENT_LANGUAGE
)<
/string
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
<
string
>
$
(
EXECUTABLE_NAME
)<
/string
>
<
k
e
y
>
CFBundleIdentifier
<
/k
e
y
>
<
string
>
$
(
PRODUCT_BUNDLE_IDENTIFIER
)<
/string
>
<
k
e
y
>
CFBundleInfoDictionaryVersion
<
/k
e
y
>
<
string
>
6.0
<
/string
>
<
k
e
y
>
CFBundleName
<
/k
e
y
>
<
string
>
$
(
PRODUCT_NAME
)<
/string
>
<
k
e
y
>
CFBundlePackageType
<
/k
e
y
>
<
string
>
BNDL
<
/string
>
<
k
e
y
>
CFBundleShortVersionString
<
/k
e
y
>
<
string
>
1.0
<
/string
>
<
k
e
y
>
CFBundleVersion
<
/k
e
y
>
<
string
>
1
<
/string
>
<
/
d
i
c
t
>
<
/plist
>
Example/Podfile.lock
View file @
07cb6ce7
...
...
@@ -35,7 +35,7 @@ PODS:
- GMKit/Protocol (0.8.4):
- Masonry (= 1.1.0)
- SDWebImage (= 3.7.6)
- GMPhobos (1.
0.7
):
- GMPhobos (1.
1.2
):
- GMCache (= 0.2.3)
- GMKit
- Masonry (1.1.0)
...
...
@@ -63,11 +63,11 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639
GMKit: a30da06b84e5c4a357d427c70d1b5ec672a1f6a1
GMPhobos:
dd0026c837b0909013a9002b7f3e04f28786e24b
GMPhobos:
5d9b29fb16fb7b8f3b2983aaab8b42cefc510baa
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad
COCOAPODS: 1.6.
0.beta.2
COCOAPODS: 1.6.
1
Example/Tests/GMPhotoTest.m
View file @
07cb6ce7
...
...
@@ -27,13 +27,18 @@ NSString *const MockCityId = @"beijing";
-
(
void
)
setUp
{
[
super
setUp
];
_client
=
[
Phobos
clientWithAppName
:
MockAppName
channelId
:
MockChannelId
];
_client
.
serverAPI
=
@"http://log.test.igengmei.com/log/collect"
;
[
_client
setLogEnabled
:
NO
];
// 调试打Log模式,看情况开启
_client
.
signingType
=
PhobosSigningTypeDebug
;
_client
.
userId
=
@""
;
[
Phobos
setSharedClient
:
_client
];
}
-
(
void
)
tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[
super
tearDown
];
[
GMCache
removeObjectAtDucmentPathWithkey
:
PhobosCacheKey
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
}
/**
...
...
@@ -45,7 +50,7 @@ NSString *const MockCityId = @"beijing";
[
_client
setUserId
:
MockUserId
];
[
_client
setCurrentCityId
:
MockCityId
];
[
Phobos
track
:
MockEventId
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
uc
mentPathWithkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
ocu
mentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -59,7 +64,7 @@ NSString *const MockCityId = @"beijing";
*/
-
(
void
)
testTrackEventWithoutAttr
{
[
Phobos
track
:
MockEventId
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
uc
mentPathWithkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
ocu
mentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -74,7 +79,7 @@ NSString *const MockCityId = @"beijing";
-
(
void
)
testTrackEventWithAttr
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
[
Phobos
track
:
MockEventId
attributes
:
attr
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
uc
mentPathWithkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
ocu
mentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -95,10 +100,175 @@ NSString *const MockCityId = @"beijing";
// When
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
// Then
NSArray
*
array
=
[
GMCache
fetchObjectAtD
uc
mentPathWithkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
ocu
mentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array should be empty"
);
}
/**
* @brief 测试立即发送带参数事件成功,不应该清除不立即发送的埋点
*
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithAttrAndSendNowDonotClearNormal
{
// Given
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
NSDictionary
*
sendNowAttr
=
@{
@"attr"
:
@"track_attr_send_now"
};
// When
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
NO
];
// When
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"array shouldn't be empty"
);
}
/**
* @brief 测试二次立即发送带参数事件成功,不应该重复发送上一条
*
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithDoubleAttrAndSendNow
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
// 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 TODO
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
25
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
25
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
});
});
}
/**
* @brief 测试不立即发送带参数事件成功后,数据会被清除
*
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithDoubleAttrAndNoSendNow
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
//
[
Phobos
track
:
MockEventId
attributes
:
attr
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
}
/**
* @brief 测试不实时和实时穿插 1
*
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithSendNowAndNoSendNowOne
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
NSDictionary
*
sendNowAttr
=
@{
@"attr"
:
@"track_attr_send_now"
};
for
(
int
i
=
0
;
i
<
30
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
31
,
@"array shouldn't be empty"
);
}
/**
* @brief 测试不实时和实时穿插 2
*
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithSendNowAndNoSendNowTwo
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
NSDictionary
*
sendNowAttr
=
@{
@"attr"
:
@"track_attr_send_now"
};
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
3
,
@"array shouldn't be empty"
);
}
/**
* @brief 测试不实时和实时穿插 3
*
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithSendNowAndNoSendNowThree
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
//
[
Phobos
track
:
MockEventId
attributes
:
attr
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
}
-
(
void
)
verfiyDict
:
(
NSDictionary
*
)
dict
{
NSArray
*
keys
=
[
dict
allKeys
];
XCTAssertTrue
([
keys
containsObject
:
@"type"
],
@"Missing type"
);
...
...
@@ -139,7 +309,7 @@ NSString *const MockCityId = @"beijing";
[
controller
viewWillAppear
:
true
];
[
controller
viewWillDisappear
:
true
];
[
self
paramUnNilCheck
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
uc
mentPathWithkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
ocu
mentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
NSDictionary
*
dic
=
array
[
0
][
@"params"
];
...
...
@@ -153,7 +323,7 @@ NSString *const MockCityId = @"beijing";
}
-
(
void
)
paramUnNilCheck
{
NSArray
*
array
=
[
GMCache
fetchObjectAtD
uc
mentPathWithkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
GMCache
fetchObjectAtD
ocu
mentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
NSDictionary
*
dic
=
array
[
0
][
@"params"
];
...
...
GMPhobos/Classes/Phobos.m
View file @
07cb6ce7
...
...
@@ -565,7 +565,9 @@ static NSString *sdkVersion = @"110";
//2.把缓存区的数据发送给服务器
[
self
sendArray
];
//3.把原有的数据删除
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
if
(
clean
)
{
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
}
}
@catch
(
NSException
*
exception
)
{
phobosLog
(
exception
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment