Skip to content

Commit e41b3f8

Browse files
committed
添加单元测试
1 parent 3007a32 commit e41b3f8

File tree

6 files changed

+436
-0
lines changed

6 files changed

+436
-0
lines changed

AJRealmDB/AJRealmDB.xcodeproj/project.pbxproj

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
CC1639491DDDEA160083825A /* AJRealmDBTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC1639481DDDEA160083825A /* AJRealmDBTests.m */; };
11+
CC1639511DDDEAA10083825A /* DBWriteTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC1639501DDDEAA10083825A /* DBWriteTests.m */; };
12+
CC5FCC1C1DE1801800CB7514 /* Realm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBF3449C1DD0598F00CEEA30 /* Realm.framework */; };
13+
CC5FCC201DE1A9DD00CB7514 /* DBUpdateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC5FCC1F1DE1A9DD00CB7514 /* DBUpdateTests.m */; };
14+
CCF688E01DE3448800AD7E4F /* DBDeleteTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF688DF1DE3448800AD7E4F /* DBDeleteTests.m */; };
1015
EBF3443E1DD0584600CEEA30 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EBF3443D1DD0584600CEEA30 /* main.m */; };
1116
EBF344411DD0584600CEEA30 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EBF344401DD0584600CEEA30 /* AppDelegate.m */; };
1217
EBF344471DD0584600CEEA30 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EBF344451DD0584600CEEA30 /* Main.storyboard */; };
@@ -31,7 +36,23 @@
3136
EBF344A51DD05ADD00CEEA30 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = EBF344A41DD05ADD00CEEA30 /* libz.tbd */; };
3237
/* End PBXBuildFile section */
3338

39+
/* Begin PBXContainerItemProxy section */
40+
CC16394B1DDDEA160083825A /* PBXContainerItemProxy */ = {
41+
isa = PBXContainerItemProxy;
42+
containerPortal = EBF344311DD0584600CEEA30 /* Project object */;
43+
proxyType = 1;
44+
remoteGlobalIDString = EBF344381DD0584600CEEA30;
45+
remoteInfo = AJRealmDB;
46+
};
47+
/* End PBXContainerItemProxy section */
48+
3449
/* Begin PBXFileReference section */
50+
CC1639461DDDEA160083825A /* AJRealmDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AJRealmDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
51+
CC1639481DDDEA160083825A /* AJRealmDBTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AJRealmDBTests.m; sourceTree = "<group>"; };
52+
CC16394A1DDDEA160083825A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
53+
CC1639501DDDEAA10083825A /* DBWriteTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBWriteTests.m; sourceTree = "<group>"; };
54+
CC5FCC1F1DE1A9DD00CB7514 /* DBUpdateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBUpdateTests.m; sourceTree = "<group>"; };
55+
CCF688DF1DE3448800AD7E4F /* DBDeleteTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBDeleteTests.m; sourceTree = "<group>"; };
3556
EBF344391DD0584600CEEA30 /* AJRealmDB.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AJRealmDB.app; sourceTree = BUILT_PRODUCTS_DIR; };
3657
EBF3443D1DD0584600CEEA30 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3758
EBF3443F1DD0584600CEEA30 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -75,6 +96,14 @@
7596
/* End PBXFileReference section */
7697

7798
/* Begin PBXFrameworksBuildPhase section */
99+
CC1639431DDDEA160083825A /* Frameworks */ = {
100+
isa = PBXFrameworksBuildPhase;
101+
buildActionMask = 2147483647;
102+
files = (
103+
CC5FCC1C1DE1801800CB7514 /* Realm.framework in Frameworks */,
104+
);
105+
runOnlyForDeploymentPostprocessing = 0;
106+
};
78107
EBF344361DD0584600CEEA30 /* Frameworks */ = {
79108
isa = PBXFrameworksBuildPhase;
80109
buildActionMask = 2147483647;
@@ -88,10 +117,23 @@
88117
/* End PBXFrameworksBuildPhase section */
89118

90119
/* Begin PBXGroup section */
120+
CC1639471DDDEA160083825A /* AJRealmDBTests */ = {
121+
isa = PBXGroup;
122+
children = (
123+
CC1639481DDDEA160083825A /* AJRealmDBTests.m */,
124+
CC16394A1DDDEA160083825A /* Info.plist */,
125+
CC1639501DDDEAA10083825A /* DBWriteTests.m */,
126+
CC5FCC1F1DE1A9DD00CB7514 /* DBUpdateTests.m */,
127+
CCF688DF1DE3448800AD7E4F /* DBDeleteTests.m */,
128+
);
129+
path = AJRealmDBTests;
130+
sourceTree = "<group>";
131+
};
91132
EBF344301DD0584600CEEA30 = {
92133
isa = PBXGroup;
93134
children = (
94135
EBF3443B1DD0584600CEEA30 /* AJRealmDB */,
136+
CC1639471DDDEA160083825A /* AJRealmDBTests */,
95137
EBF3443A1DD0584600CEEA30 /* Products */,
96138
EBF3449F1DD059B000CEEA30 /* Frameworks */,
97139
);
@@ -101,6 +143,7 @@
101143
isa = PBXGroup;
102144
children = (
103145
EBF344391DD0584600CEEA30 /* AJRealmDB.app */,
146+
CC1639461DDDEA160083825A /* AJRealmDBTests.xctest */,
104147
);
105148
name = Products;
106149
sourceTree = "<group>";
@@ -193,6 +236,24 @@
193236
/* End PBXGroup section */
194237

195238
/* Begin PBXNativeTarget section */
239+
CC1639451DDDEA160083825A /* AJRealmDBTests */ = {
240+
isa = PBXNativeTarget;
241+
buildConfigurationList = CC16394D1DDDEA160083825A /* Build configuration list for PBXNativeTarget "AJRealmDBTests" */;
242+
buildPhases = (
243+
CC1639421DDDEA160083825A /* Sources */,
244+
CC1639431DDDEA160083825A /* Frameworks */,
245+
CC1639441DDDEA160083825A /* Resources */,
246+
);
247+
buildRules = (
248+
);
249+
dependencies = (
250+
CC16394C1DDDEA160083825A /* PBXTargetDependency */,
251+
);
252+
name = AJRealmDBTests;
253+
productName = AJRealmDBTests;
254+
productReference = CC1639461DDDEA160083825A /* AJRealmDBTests.xctest */;
255+
productType = "com.apple.product-type.bundle.unit-test";
256+
};
196257
EBF344381DD0584600CEEA30 /* AJRealmDB */ = {
197258
isa = PBXNativeTarget;
198259
buildConfigurationList = EBF3445B1DD0584600CEEA30 /* Build configuration list for PBXNativeTarget "AJRealmDB" */;
@@ -219,6 +280,11 @@
219280
LastUpgradeCheck = 0810;
220281
ORGANIZATIONNAME = AbooJan;
221282
TargetAttributes = {
283+
CC1639451DDDEA160083825A = {
284+
CreatedOnToolsVersion = 8.1;
285+
ProvisioningStyle = Automatic;
286+
TestTargetID = EBF344381DD0584600CEEA30;
287+
};
222288
EBF344381DD0584600CEEA30 = {
223289
CreatedOnToolsVersion = 8.1;
224290
ProvisioningStyle = Automatic;
@@ -239,11 +305,19 @@
239305
projectRoot = "";
240306
targets = (
241307
EBF344381DD0584600CEEA30 /* AJRealmDB */,
308+
CC1639451DDDEA160083825A /* AJRealmDBTests */,
242309
);
243310
};
244311
/* End PBXProject section */
245312

246313
/* Begin PBXResourcesBuildPhase section */
314+
CC1639441DDDEA160083825A /* Resources */ = {
315+
isa = PBXResourcesBuildPhase;
316+
buildActionMask = 2147483647;
317+
files = (
318+
);
319+
runOnlyForDeploymentPostprocessing = 0;
320+
};
247321
EBF344371DD0584600CEEA30 /* Resources */ = {
248322
isa = PBXResourcesBuildPhase;
249323
buildActionMask = 2147483647;
@@ -257,6 +331,17 @@
257331
/* End PBXResourcesBuildPhase section */
258332

259333
/* Begin PBXSourcesBuildPhase section */
334+
CC1639421DDDEA160083825A /* Sources */ = {
335+
isa = PBXSourcesBuildPhase;
336+
buildActionMask = 2147483647;
337+
files = (
338+
CC1639491DDDEA160083825A /* AJRealmDBTests.m in Sources */,
339+
CC5FCC201DE1A9DD00CB7514 /* DBUpdateTests.m in Sources */,
340+
CCF688E01DE3448800AD7E4F /* DBDeleteTests.m in Sources */,
341+
CC1639511DDDEAA10083825A /* DBWriteTests.m in Sources */,
342+
);
343+
runOnlyForDeploymentPostprocessing = 0;
344+
};
260345
EBF344351DD0584600CEEA30 /* Sources */ = {
261346
isa = PBXSourcesBuildPhase;
262347
buildActionMask = 2147483647;
@@ -282,6 +367,14 @@
282367
};
283368
/* End PBXSourcesBuildPhase section */
284369

370+
/* Begin PBXTargetDependency section */
371+
CC16394C1DDDEA160083825A /* PBXTargetDependency */ = {
372+
isa = PBXTargetDependency;
373+
target = EBF344381DD0584600CEEA30 /* AJRealmDB */;
374+
targetProxy = CC16394B1DDDEA160083825A /* PBXContainerItemProxy */;
375+
};
376+
/* End PBXTargetDependency section */
377+
285378
/* Begin PBXVariantGroup section */
286379
EBF344451DD0584600CEEA30 /* Main.storyboard */ = {
287380
isa = PBXVariantGroup;
@@ -302,6 +395,38 @@
302395
/* End PBXVariantGroup section */
303396

304397
/* Begin XCBuildConfiguration section */
398+
CC16394E1DDDEA160083825A /* Debug */ = {
399+
isa = XCBuildConfiguration;
400+
buildSettings = {
401+
BUNDLE_LOADER = "$(TEST_HOST)";
402+
FRAMEWORK_SEARCH_PATHS = (
403+
"$(inherited)",
404+
"$(PROJECT_DIR)/AJRealmDB",
405+
);
406+
INFOPLIST_FILE = AJRealmDBTests/Info.plist;
407+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
408+
PRODUCT_BUNDLE_IDENTIFIER = com.aboo.AJRealmDBTests;
409+
PRODUCT_NAME = "$(TARGET_NAME)";
410+
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AJRealmDB.app/AJRealmDB";
411+
};
412+
name = Debug;
413+
};
414+
CC16394F1DDDEA160083825A /* Release */ = {
415+
isa = XCBuildConfiguration;
416+
buildSettings = {
417+
BUNDLE_LOADER = "$(TEST_HOST)";
418+
FRAMEWORK_SEARCH_PATHS = (
419+
"$(inherited)",
420+
"$(PROJECT_DIR)/AJRealmDB",
421+
);
422+
INFOPLIST_FILE = AJRealmDBTests/Info.plist;
423+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
424+
PRODUCT_BUNDLE_IDENTIFIER = com.aboo.AJRealmDBTests;
425+
PRODUCT_NAME = "$(TARGET_NAME)";
426+
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AJRealmDB.app/AJRealmDB";
427+
};
428+
name = Release;
429+
};
305430
EBF344591DD0584600CEEA30 /* Debug */ = {
306431
isa = XCBuildConfiguration;
307432
buildSettings = {
@@ -403,6 +528,7 @@
403528
INFOPLIST_FILE = AJRealmDB/Info.plist;
404529
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
405530
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
531+
LIBRARY_SEARCH_PATHS = "";
406532
PRODUCT_BUNDLE_IDENTIFIER = com.aboo.AJRealmDB;
407533
PRODUCT_NAME = "$(TARGET_NAME)";
408534
};
@@ -419,6 +545,7 @@
419545
INFOPLIST_FILE = AJRealmDB/Info.plist;
420546
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
421547
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
548+
LIBRARY_SEARCH_PATHS = "";
422549
PRODUCT_BUNDLE_IDENTIFIER = com.aboo.AJRealmDB;
423550
PRODUCT_NAME = "$(TARGET_NAME)";
424551
};
@@ -427,6 +554,15 @@
427554
/* End XCBuildConfiguration section */
428555

429556
/* Begin XCConfigurationList section */
557+
CC16394D1DDDEA160083825A /* Build configuration list for PBXNativeTarget "AJRealmDBTests" */ = {
558+
isa = XCConfigurationList;
559+
buildConfigurations = (
560+
CC16394E1DDDEA160083825A /* Debug */,
561+
CC16394F1DDDEA160083825A /* Release */,
562+
);
563+
defaultConfigurationIsVisible = 0;
564+
defaultConfigurationName = Release;
565+
};
430566
EBF344341DD0584600CEEA30 /* Build configuration list for PBXProject "AJRealmDB" */ = {
431567
isa = XCConfigurationList;
432568
buildConfigurations = (
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// AJRealmDBTests.m
3+
// AJRealmDBTests
4+
//
5+
// Created by aboojan on 2016/11/17.
6+
// Copyright © 2016年 AbooJan. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
11+
@interface AJRealmDBTests : XCTestCase
12+
13+
@end
14+
15+
@implementation AJRealmDBTests
16+
17+
- (void)setUp {
18+
[super setUp];
19+
// Put setup code here. This method is called before the invocation of each test method in the class.
20+
}
21+
22+
- (void)tearDown {
23+
// Put teardown code here. This method is called after the invocation of each test method in the class.
24+
[super tearDown];
25+
}
26+
27+
- (void)testExample {
28+
// This is an example of a functional test case.
29+
// Use XCTAssert and related functions to verify your tests produce the correct results.
30+
}
31+
32+
- (void)testPerformanceExample {
33+
// This is an example of a performance test case.
34+
[self measureBlock:^{
35+
// Put the code you want to measure the time of here.
36+
}];
37+
}
38+
39+
@end
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// DBDeleteTests.m
3+
// AJRealmDB
4+
//
5+
// Created by aboojan on 2016/11/21.
6+
// Copyright © 2016年 AbooJan. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "TestUserBean.h"
11+
#import "AJDBManager.h"
12+
13+
@interface DBDeleteTests : XCTestCase
14+
15+
@end
16+
17+
@implementation DBDeleteTests
18+
19+
- (void)setUp {
20+
[super setUp];
21+
22+
NSMutableArray *userArray = [NSMutableArray array];
23+
for (NSInteger i = 0; i < 10; i++) {
24+
TestUserBean *user = [TestUserBean new];
25+
user.ID = [NSString stringWithFormat:@"%ld", (long)(200+i)];
26+
user.name = [NSString stringWithFormat:@"TestUser_%ld", (long)i];
27+
[userArray addObject:user];
28+
}
29+
30+
[AJDBManager writeObjArray:userArray];
31+
}
32+
33+
- (void)tearDown {
34+
[super tearDown];
35+
}
36+
37+
- (void)testExample {
38+
}
39+
40+
- (void)testPerformanceExample {
41+
// This is an example of a performance test case.
42+
[self measureBlock:^{
43+
// Put the code you want to measure the time of here.
44+
}];
45+
}
46+
47+
- (void)testDeleteSingleItem
48+
{
49+
TestUserBean *oldUser = [AJDBManager queryObjWithPrimaryKeyValue:@"201" targetClass:[TestUserBean class]];
50+
XCTAssert(oldUser != nil, @"没有数据");
51+
52+
[AJDBManager deleteObj:oldUser];
53+
54+
TestUserBean *newUser = [AJDBManager queryObjWithPrimaryKeyValue:@"201" targetClass:[TestUserBean class]];
55+
XCTAssert(newUser == nil, @"删除数据失败");
56+
}
57+
58+
- (void)testDeleteItems
59+
{
60+
NSArray *userArray = [AJDBManager queryAllObj:[TestUserBean class]];
61+
XCTAssert(userArray.count > 0, @"空数据");
62+
63+
[AJDBManager deleteObjs:userArray];
64+
65+
NSArray *changedUserArray = [AJDBManager queryAllObj:[TestUserBean class]];
66+
XCTAssert(changedUserArray.count == 0, @"批量数据删除失败");
67+
}
68+
69+
@end

0 commit comments

Comments
 (0)