Commit 07cb6ce7 authored by 乔金柱's avatar 乔金柱

Merge branch 'jql/test' into 'master'

添加单元测试、修改普通埋点删除问题

See merge request !33
parents 8a3ae2ff 098d1243
This diff is collapsed.
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
<TestableReference <TestableReference
...@@ -44,6 +43,16 @@ ...@@ -44,6 +43,16 @@
</Test> </Test>
</SkippedTests> </SkippedTests>
</TestableReference> </TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "63EFAB0D22658352005EEAC6"
BuildableName = "GMPhobos_ExampleTests.xctest"
BlueprintName = "GMPhobos_ExampleTests"
ReferencedContainer = "container:GMPhobos.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables> </Testables>
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference
...@@ -61,7 +70,6 @@ ...@@ -61,7 +70,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
......
//
// 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
...@@ -35,7 +35,7 @@ PODS: ...@@ -35,7 +35,7 @@ PODS:
- GMKit/Protocol (0.8.4): - GMKit/Protocol (0.8.4):
- Masonry (= 1.1.0) - Masonry (= 1.1.0)
- SDWebImage (= 3.7.6) - SDWebImage (= 3.7.6)
- GMPhobos (1.0.7): - GMPhobos (1.1.2):
- GMCache (= 0.2.3) - GMCache (= 0.2.3)
- GMKit - GMKit
- Masonry (1.1.0) - Masonry (1.1.0)
...@@ -63,11 +63,11 @@ EXTERNAL SOURCES: ...@@ -63,11 +63,11 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639 GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639
GMKit: a30da06b84e5c4a357d427c70d1b5ec672a1f6a1 GMKit: a30da06b84e5c4a357d427c70d1b5ec672a1f6a1
GMPhobos: dd0026c837b0909013a9002b7f3e04f28786e24b GMPhobos: 5d9b29fb16fb7b8f3b2983aaab8b42cefc510baa
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201 Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9 SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad
COCOAPODS: 1.6.0.beta.2 COCOAPODS: 1.6.1
...@@ -27,13 +27,18 @@ NSString *const MockCityId = @"beijing"; ...@@ -27,13 +27,18 @@ NSString *const MockCityId = @"beijing";
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
_client = [Phobos clientWithAppName:MockAppName channelId:MockChannelId]; _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]; [Phobos setSharedClient:_client];
} }
- (void)tearDown { - (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class. // Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown]; [super tearDown];
[GMCache removeObjectAtDucmentPathWithkey:PhobosCacheKey]; [GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
[GMCache removeObjectAtDocumentPathWithkey:PhobosTempCacheKey];
} }
/** /**
...@@ -45,7 +50,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -45,7 +50,7 @@ NSString *const MockCityId = @"beijing";
[_client setUserId:MockUserId]; [_client setUserId:MockUserId];
[_client setCurrentCityId:MockCityId]; [_client setCurrentCityId:MockCityId];
[Phobos track:MockEventId]; [Phobos track:MockEventId];
NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -59,7 +64,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -59,7 +64,7 @@ NSString *const MockCityId = @"beijing";
*/ */
- (void)testTrackEventWithoutAttr{ - (void)testTrackEventWithoutAttr{
[Phobos track:MockEventId]; [Phobos track:MockEventId];
NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -74,7 +79,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -74,7 +79,7 @@ NSString *const MockCityId = @"beijing";
- (void)testTrackEventWithAttr{ - (void)testTrackEventWithAttr{
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -95,10 +100,175 @@ NSString *const MockCityId = @"beijing"; ...@@ -95,10 +100,175 @@ NSString *const MockCityId = @"beijing";
// When // When
[Phobos track:MockEventId attributes:attr sendNow:YES]; [Phobos track:MockEventId attributes:attr sendNow:YES];
// Then // Then
NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 0, @"array should be empty"); 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{ - (void)verfiyDict:(NSDictionary *)dict{
NSArray *keys = [dict allKeys]; NSArray *keys = [dict allKeys];
XCTAssertTrue([keys containsObject:@"type"], @"Missing type"); XCTAssertTrue([keys containsObject:@"type"], @"Missing type");
...@@ -139,7 +309,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -139,7 +309,7 @@ NSString *const MockCityId = @"beijing";
[controller viewWillAppear:true]; [controller viewWillAppear:true];
[controller viewWillDisappear:true]; [controller viewWillDisappear:true];
[self paramUnNilCheck]; [self paramUnNilCheck];
NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"]; NSDictionary *dic = array[0][@"params"];
...@@ -153,7 +323,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -153,7 +323,7 @@ NSString *const MockCityId = @"beijing";
} }
- (void)paramUnNilCheck { - (void)paramUnNilCheck {
NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"]; NSDictionary *dic = array[0][@"params"];
......
...@@ -565,7 +565,9 @@ static NSString *sdkVersion = @"110"; ...@@ -565,7 +565,9 @@ static NSString *sdkVersion = @"110";
//2.把缓存区的数据发送给服务器 //2.把缓存区的数据发送给服务器
[self sendArray]; [self sendArray];
//3.把原有的数据删除 //3.把原有的数据删除
[GMCache removeObjectAtDocumentPathWithkey:PhobosTempCacheKey]; if (clean) {
[GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
}
} }
@catch (NSException *exception) { @catch (NSException *exception) {
phobosLog(exception); phobosLog(exception);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment