setup local firestore instance for unit testing

131 views
Skip to first unread message

Andy Wu

unread,
Jan 24, 2018, 11:45:39 PM1/24/18
to Firebase Google Group
Has anyone been successful setting up a local firestore instance in unit tests? I have something like below setup:

class LocalDbTests: XCTestCase {


  var db: Firestore?

  override func setUp() {

    super.setUp()

    FirebaseApp.configure()

    db = Firestore.firestore()

    // Use local db only for testing.

    let settings = FirestoreSettings()

    settings.host = "localhost"

    settings.isPersistenceEnabled = true

    db!.settings = settings

    db!.disableNetwork()

    let testData = testSingleWorkout()

    let docRef = db?.collection("coll").document("doc")

    docRef?.setData(testData.dictionary)

  }


This works fine if i write the db access code in the unittest itself. However, if i pass the `db` instance to a class in my actual target code, then query data there, i get error:

Fatal error: NSArray element failed to match the Swift Array Element type


Any idea why this is happening? Note that I am building a library project, without an app, so `FirebaseApp.configure` is called in tests. 


Reply all
Reply to author
Forward
0 new messages