Skip to content

Commit 1b1d046

Browse files
committed
ADD: 添加测试代码
1 parent 552b9ba commit 1b1d046

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

YTKKeyValueStore_Swift/YTKKeyValueStore_Swift.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public class YTKKeyValueStore_Swift: NSObject {
5555

5656
//MARK: - 初始化
5757

58-
override init(){
58+
public override init(){
5959
super.init()
6060
self.setupDB(DEFAULT_DB_NAME)
6161
}
6262

63-
init(dbName : String!){
63+
public init(dbName : String!){
6464
super.init()
6565
self.setupDB(dbName)
6666
}

YTKKeyValueStore_SwiftTests/YTKKeyValueStore_SwiftTests.swift

+57-10
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,76 @@
88

99
import UIKit
1010
import XCTest
11+
import YTKKeyValueStore_Swift
1112

1213
class YTKKeyValueStore_SwiftTests: XCTestCase {
1314

15+
private var _store : YTKKeyValueStore_Swift?
16+
private var _tableName : String?
17+
1418
override func setUp() {
1519
super.setUp()
16-
// Put setup code here. This method is called before the invocation of each test method in the class.
20+
_tableName = "test_table"
21+
_store = YTKKeyValueStore_Swift()
22+
_store?.createTable(tableName: _tableName!)
23+
_store?.clearTable(tableName: _tableName!)
1724
}
1825

1926
override func tearDown() {
20-
// Put teardown code here. This method is called after the invocation of each test method in the class.
27+
_store?.clearTable(tableName: _tableName)
28+
_store?.close()
29+
_store = nil
2130
super.tearDown()
2231
}
2332

24-
func testExample() {
25-
// This is an example of a functional test case.
26-
XCTAssert(true, "Pass")
33+
func testSaveString(){
34+
35+
let str1 = "abc"
36+
let key1 = "key1"
37+
let str2 = "abc2"
38+
let key2 = "key2"
39+
40+
_store?.putString(str1, withId: key1, intoTable: _tableName)
41+
_store?.putString(str2, withId: key2, intoTable: _tableName)
42+
43+
var result : String?
44+
45+
result = _store?.getStringById(key1, fromTable: _tableName)
46+
XCTAssertNotNil(result)
47+
XCTAssertEqual(str1, result!)
48+
49+
result = _store?.getStringById(key2, fromTable: _tableName)
50+
XCTAssertNotNil(result)
51+
XCTAssertEqual(str2, result!)
52+
53+
result = _store?.getStringById("key3", fromTable: _tableName)
54+
XCTAssertNil(result)
55+
2756
}
2857

29-
func testPerformanceExample() {
30-
// This is an example of a performance test case.
31-
self.measureBlock() {
32-
// Put the code you want to measure the time of here.
33-
}
58+
func testSaveCGFloat(){
59+
60+
let num1 : CGFloat = 1
61+
let key1 = "key1"
62+
let num2 : CGFloat = 2
63+
let key2 = "key2"
64+
65+
_store?.putNumber(num1, withId: key1, intoTable: _tableName)
66+
_store?.putNumber(num2, withId: key2, intoTable: _tableName)
67+
68+
var result : CGFloat?
69+
70+
result = _store?.getNumberById(key1, fromTable: _tableName)
71+
XCTAssertNotNil(result)
72+
XCTAssertEqual(num1, result!)
73+
74+
result = _store?.getNumberById(key2, fromTable: _tableName)
75+
XCTAssertNotNil(result)
76+
XCTAssertEqual(num2, result!)
77+
78+
result = _store?.getNumberById("key3", fromTable: _tableName)
79+
XCTAssertNil(result)
80+
3481
}
3582

3683
}

0 commit comments

Comments
 (0)