[英]Unit Testing with Firebase (Swift)
嘗試使用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()
}
Podfile:
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。 在網上找不到任何有關單元測試所需的特殊配置的信息。
Welp,無法說出具體的配置問題是什么,但這最終成為了“嘗試關閉並重新打開”解決方案之一。
pod deintegrate
pod cache clean --all
pod install
另外,與文檔直接相反,您需要在podfile中包含Firebase/Core
,否則您將無法初始化Firestore。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.