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
098d1243
Commit
098d1243
authored
Apr 16, 2019
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加单元测试
parent
dfe48e19
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
15 deletions
+118
-15
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+118
-15
No files found.
Example/Tests/GMPhotoTest.m
View file @
098d1243
...
...
@@ -27,6 +27,10 @@ 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
];
}
...
...
@@ -34,6 +38,7 @@ NSString *const MockCityId = @"beijing";
// Put teardown code here. This method is called after the invocation of each test method in the class.
[
super
tearDown
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
}
/**
...
...
@@ -107,10 +112,11 @@ NSString *const MockCityId = @"beijing";
-
(
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
:
a
ttr
sendNow
:
YES
];
[
Phobos
track
:
MockEventId
attributes
:
sendNowA
ttr
sendNow
:
YES
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"array shouldn't be empty"
);
...
...
@@ -122,21 +128,23 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithDoubleAttrAndSendNow
{
// Given
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
// When
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
// When
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
// 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 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"
);
});
});
}
/**
...
...
@@ -145,8 +153,6 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithDoubleAttrAndNoSendNow
{
// remove 保证PhobosCacheKey起始数据为空
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
//
[
Phobos
track
:
MockEventId
attributes
:
attr
];
...
...
@@ -166,6 +172,103 @@ NSString *const MockCityId = @"beijing";
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"
);
...
...
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