Skip to content

Commit f02fdf2

Browse files
Unit Test 추가
1 parent 0db0529 commit f02fdf2

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

WTUserDefaults.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
915E58C71F15CECF006DE437 /* WTUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 915E58B91F15CECF006DE437 /* WTUserDefaults.h */; settings = {ATTRIBUTES = (Public, ); }; };
1313
915E58D21F15CF0C006DE437 /* WTUserDefaultsHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 915E58D01F15CF0C006DE437 /* WTUserDefaultsHelper.swift */; };
1414
915E58D31F15CF0C006DE437 /* WTUserDefaultsProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 915E58D11F15CF0C006DE437 /* WTUserDefaultsProtocol.swift */; };
15+
916D82CE1F1709B80073B593 /* WTUserDefaultsHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 915E58D01F15CF0C006DE437 /* WTUserDefaultsHelper.swift */; };
16+
916D82CF1F1709B80073B593 /* WTUserDefaultsProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 915E58D11F15CF0C006DE437 /* WTUserDefaultsProtocol.swift */; };
1517
/* End PBXBuildFile section */
1618

1719
/* Begin PBXContainerItemProxy section */
@@ -214,6 +216,8 @@
214216
isa = PBXSourcesBuildPhase;
215217
buildActionMask = 2147483647;
216218
files = (
219+
916D82CE1F1709B80073B593 /* WTUserDefaultsHelper.swift in Sources */,
220+
916D82CF1F1709B80073B593 /* WTUserDefaultsProtocol.swift in Sources */,
217221
915E58C51F15CECF006DE437 /* WTUserDefaultsTests.swift in Sources */,
218222
);
219223
runOnlyForDeploymentPostprocessing = 0;
@@ -338,6 +342,7 @@
338342
915E58CB1F15CECF006DE437 /* Debug */ = {
339343
isa = XCBuildConfiguration;
340344
buildSettings = {
345+
APPLICATION_EXTENSION_API_ONLY = YES;
341346
ARCHS = "$(ARCHS_STANDARD)";
342347
CLANG_ENABLE_MODULES = YES;
343348
CODE_SIGN_IDENTITY = "";
@@ -365,6 +370,7 @@
365370
915E58CC1F15CECF006DE437 /* Release */ = {
366371
isa = XCBuildConfiguration;
367372
buildSettings = {
373+
APPLICATION_EXTENSION_API_ONLY = YES;
368374
ARCHS = "$(ARCHS_STANDARD)";
369375
CLANG_ENABLE_MODULES = YES;
370376
CODE_SIGN_IDENTITY = "";

WTUserDefaults/WTUserDefaultsHelper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class WTUserDefaultsHelper : WTUserDefaultsProtocol {
3636
return userDefaults.object(forKey:forKey)
3737
}
3838

39-
public func array(forKey:String) -> [Any]? {
39+
public func getArray(forKey:String) -> [Any]? {
4040
return userDefaults.array(forKey: forKey)
4141
}
4242

WTUserDefaults/WTUserDefaultsProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public protocol WTUserDefaultsProtocol {
1414
func getBool(forKey: String) -> Bool
1515
func getInteger(forKey: String) -> Int
1616
func getObject(forKey: String) -> Any?
17-
func array(forKey: String) -> [Any]?
17+
func getArray(forKey: String) -> [Any]?
1818
func set(_ value:Any, forKey: String)
1919
}

WTUserDefaultsTests/WTUserDefaultsTests.swift

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,87 @@
77
//
88

99
import XCTest
10-
@testable import WTUserDefaults
1110

1211
class WTUserDefaultsTests: XCTestCase {
12+
var userDefaults:WTUserDefaultsHelper?
1313

1414
override func setUp() {
1515
super.setUp()
1616
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
self.userDefaults = WTUserDefaultsHelper()
1718
}
1819

1920
override func tearDown() {
2021
// Put teardown code here. This method is called after the invocation of each test method in the class.
2122
super.tearDown()
2223
}
2324

24-
func testExample() {
25-
// This is an example of a functional test case.
26-
// Use XCTAssert and related functions to verify your tests produce the correct results.
25+
func testSetAndGetBool() {
26+
guard let defaults = userDefaults else { return }
27+
let stringKey = "ABC"
28+
defaults.set(true, forKey: stringKey)
29+
var ret = defaults.getBool(forKey: stringKey)
30+
XCTAssert(ret)
31+
defaults.set(false, forKey: stringKey)
32+
ret = defaults.getBool(forKey: stringKey)
33+
XCTAssert(false == ret)
2734
}
2835

29-
func testPerformanceExample() {
30-
// This is an example of a performance test case.
31-
self.measure {
32-
// Put the code you want to measure the time of here.
33-
}
36+
func testSetAndGetInteger() {
37+
guard let defaults = userDefaults else { return }
38+
let stringKey = "123"
39+
defaults.set(1, forKey: stringKey)
40+
var ret = defaults.getInteger(forKey: stringKey)
41+
XCTAssert(1 == ret)
42+
defaults.set(2, forKey: stringKey)
43+
ret = defaults.getInteger(forKey: stringKey)
44+
XCTAssert(2 == ret)
45+
defaults.set(3, forKey: stringKey)
46+
ret = defaults.getInteger(forKey: stringKey)
47+
XCTAssert(3 == ret)
48+
}
49+
50+
func testSetAndGetObject() {
51+
guard let defaults = userDefaults else { return }
52+
let stringKey = "KeyString"
53+
defaults.set("ABC", forKey: stringKey)
54+
var ret = defaults.getObject(forKey: stringKey) as? String
55+
XCTAssert("ABC" == ret)
56+
defaults.set("CDE", forKey: stringKey)
57+
ret = defaults.getObject(forKey: stringKey) as? String
58+
XCTAssert("CDE" == ret)
59+
defaults.set("QWER", forKey: stringKey)
60+
ret = defaults.getObject(forKey: stringKey) as? String
61+
XCTAssert("QWER" == ret)
62+
}
63+
64+
func testSetAndGetArray() {
65+
guard let defaults = userDefaults else { return }
66+
let stringKey = "ArrayTEST"
67+
var array = ["ABC"]
68+
defaults.set(array, forKey: stringKey)
69+
var ret = defaults.getArray(forKey: stringKey) as? [String]
70+
XCTAssert(1 == ret?.count)
71+
XCTAssert("ABC" == ret?[0])
72+
73+
array = ["ABC", "CDE"]
74+
defaults.set(array, forKey: stringKey)
75+
ret = defaults.getArray(forKey: stringKey) as? [String]
76+
XCTAssert(2 == ret?.count)
77+
XCTAssert("CDE" == ret?[1])
78+
79+
array = ["ABC", "CDE", "123"]
80+
defaults.set(array, forKey: stringKey)
81+
ret = defaults.getArray(forKey: stringKey) as? [String]
82+
XCTAssert(3 == ret?.count)
83+
XCTAssert("123" == ret?[2])
84+
85+
array = ["ABC", "CDE", "123", "!@#"]
86+
defaults.set(array, forKey: stringKey)
87+
ret = defaults.getArray(forKey: stringKey) as? [String]
88+
XCTAssert(4 == ret?.count)
89+
XCTAssert("!@#" == ret?[3])
90+
3491
}
3592

3693
}

0 commit comments

Comments
 (0)