@@ -16,6 +16,14 @@ import XCTest
16
16
@testable import FirebaseCore
17
17
@testable import FirebaseMLModelDownloader
18
18
19
+ /// Mock options to configure default Firebase app.
20
+ private enum MockOptions {
21
+ static let appID = " 1:123:ios:123abc "
22
+ static let gcmSenderID = " mock-sender-id "
23
+ static let projectID = " mock-project-id "
24
+ static let apiKey = " ABcdEf-APIKeyWithValidFormat_0123456789 "
25
+ }
26
+
19
27
extension UserDefaults {
20
28
/// For testing: returns a new cleared instance of user defaults.
21
29
static func getTestInstance( ) -> UserDefaults {
@@ -27,16 +35,23 @@ extension UserDefaults {
27
35
}
28
36
}
29
37
30
- // TODO: break this up into separate unit and integration tests
31
- final class ModelDownloaderTests : XCTestCase {
38
+ final class ModelDownloaderUnitTests : XCTestCase {
32
39
override class func setUp( ) {
33
- super. setUp ( )
34
- FirebaseApp . configure ( )
40
+ let options = FirebaseOptions (
41
+ googleAppID: MockOptions . appID,
42
+ gcmSenderID: MockOptions . gcmSenderID
43
+ )
44
+ options. apiKey = MockOptions . apiKey
45
+ options. projectID = MockOptions . projectID
46
+ FirebaseApp . configure ( options: options)
35
47
}
36
48
37
49
/// Unit test for reading and writing to user defaults.
38
50
func testUserDefaults( ) {
39
- let testApp = FirebaseApp . app ( ) !
51
+ guard let testApp = FirebaseApp . app ( ) else {
52
+ XCTFail ( " Default app was not configured. " )
53
+ return
54
+ }
40
55
let functionName = #function
41
56
let testModelName = " \( functionName) -test-model "
42
57
let modelInfo = ModelInfo (
@@ -52,74 +67,16 @@ final class ModelDownloaderTests: XCTestCase {
52
67
XCTAssertEqual ( modelInfo. path, nil )
53
68
}
54
69
55
- /// Test to retrieve FIS token - makes an actual network call.
56
- // TODO: Move this into a separate integration test and add unit test with mocks.
57
- func testGetAuthToken( ) {
58
- let testApp = FirebaseApp . app ( ) !
59
- let testModelName = " image-classification "
60
- let modelInfoRetriever = ModelInfoRetriever (
61
- app: testApp,
62
- modelName: testModelName,
63
- defaults: . getTestInstance( )
64
- )
65
- let expectation = self . expectation ( description: " Wait for FIS auth token. " )
66
- modelInfoRetriever. getAuthToken ( completion: { result in
67
- switch result {
68
- case let . success( token) :
69
- XCTAssertNotNil ( token)
70
- case let . failure( error) :
71
- XCTFail ( error. localizedDescription)
72
- }
73
- expectation. fulfill ( )
74
-
75
- } )
76
- waitForExpectations ( timeout: 5 , handler: nil )
77
- }
78
-
79
- /// Test to download model info - makes an actual network call.
80
- // TODO: Move this into a separate integration test and add unit test with mocks.
81
- func testDownloadModelInfo( ) {
82
- let testApp = FirebaseApp . app ( ) !
83
- let testModelName = " pose-detection "
84
- let modelInfoRetriever = ModelInfoRetriever (
85
- app: testApp,
86
- modelName: testModelName,
87
- defaults: . getTestInstance( )
88
- )
89
- let downloadExpectation = expectation ( description: " Wait for model info to download. " )
90
- modelInfoRetriever. downloadModelInfo ( completion: { error in
91
- XCTAssertNil ( error)
92
- guard let modelInfo = modelInfoRetriever. modelInfo else {
93
- XCTFail ( " Empty model info. " )
94
- return
95
- }
96
- XCTAssertNotEqual ( modelInfo. downloadURL, " " )
97
- XCTAssertNotEqual ( modelInfo. modelHash, " " )
98
- XCTAssertGreaterThan ( modelInfo. size, 0 )
99
- downloadExpectation. fulfill ( )
100
- } )
101
-
102
- waitForExpectations ( timeout: 5 , handler: nil )
103
-
104
- let retrieveExpectation = expectation ( description: " Wait for model info to be retrieved. " )
105
- modelInfoRetriever. downloadModelInfo ( completion: { error in
106
- XCTAssertNil ( error)
107
- guard let modelInfo = modelInfoRetriever. modelInfo else {
108
- XCTFail ( " Empty model info. " )
109
- return
110
- }
111
- XCTAssertNotEqual ( modelInfo. downloadURL, " " )
112
- XCTAssertNotEqual ( modelInfo. modelHash, " " )
113
- XCTAssertGreaterThan ( modelInfo. size, 0 )
114
- retrieveExpectation. fulfill ( )
115
- } )
116
-
117
- waitForExpectations ( timeout: 500 , handler: nil )
118
- }
70
+ /// Test to download model info.
71
+ // TODO: Add unit test with mocks.
72
+ func testDownloadModelInfo( ) { }
119
73
120
74
/// Unit test to save model info to user defaults.
121
75
func testSaveModelInfo( ) {
122
- let testApp = FirebaseApp . app ( ) !
76
+ guard let testApp = FirebaseApp . app ( ) else {
77
+ XCTFail ( " Default app was not configured. " )
78
+ return
79
+ }
123
80
let functionName = #function
124
81
let testModelName = " \( functionName) -test-model "
125
82
let modelInfoRetriever = ModelInfoRetriever (
0 commit comments