【发布时间】:2019-09-07 20:13:50
【问题描述】:
尝试使用 Firebase 进行一些简单的单元测试,但由于某种原因 Firestore 无法初始化:
ModelTests.swift:
func testFirebase() throws
{
// THIS IS ALWAYS "UNINITIALIZED"
let db = Firestore.firestore()
// Because db isn't initialized correctly, this ref will always be nil.
let ref: DocumentReference? = db.document("unit_testing/xxx")
ref?.setData([
"id" : "someID",
"name" : "goldenjoe",
"another" : "bmus",
"testDate" : Date()
],
merge: true,
completion: { err in
if let err = err {
print("Error adding document: \(err)")
} else {
print("Document added with ID: \(ref!.documentID)")
}
}
)
}
AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Set up Firestore
FirebaseApp.configure()
}
Pod 文件:
platform :ios, '11.0'
target 'MyWork' do
use_frameworks!
# ignore all warnings from all pods
inhibit_all_warnings!
# Pods for MyWork
pod 'CoreXLSX'
pod 'Eureka'
pod 'Firebase/Firestore'
pod 'Firebase/Auth'
pod 'ProgressHUD'
#pod 'GoogleSignIn'
pod 'SteviaLayout'
target 'MyWorkTests' do
inherit! :complete
end
end
但是,当我正常运行应用程序时,我可以在应用程序的其他部分正常使用 Firebase。在网上找不到任何有关单元测试所需的特殊配置的信息。
【问题讨论】:
标签: ios swift xcode firebase cocoapods