CouchbaseLiteSwift Unit Test/Mock

We would like to mock out the CBLite dependency in our swift iOS app.
Particularly CouchbaseLiteSwift.Database and CouchbaseLiteSwift.Collection classes.

Unfortunately, CouchbaseLiteSwift.Database is marked final and does not conform to a protocol. CouchbaseLiteSwift.Collection does conform to CouchbaseLiteSwift.CollectionChangeObservable, CouchbaseLiteSwift.Indexable, but not all the methods do.

We have our ideas on how to do this, which is to put it under a new protocol that we create and conform the Database and Collection classes to that.

protocol MyDatabase {
//existing CBlite methods

extension Database: MyDatabase {}
And then pass around the protocol type of MyDatabase to call sites in the code.

We don’t want to spin up a full fledged Database instance for each unit test.
What is the official recommendation from the core CB swift team?

I am just a developer (and for the Android product at that). Making our API mockable, though, seems to me to be a really, really good idea. I am going to add it as a feature request.
I can guarantee that, even if we decide to support such a feature, it will not arrive for quite a while. In the main time, I think that your idea:

  • A protocol that is all of the Database API that you need
  • A proxy that implements that protocol and forwards it to an instance of Database

… seems like an excellent solution.

Thanks @blake.meike ! Appreciate the response and idea :bowing_man: