I've been searching for so long about how to design testable classes in Swift but every information site just describe basic stuff like how to test, how to assert, why is testing good...
My current design (which I'm not so sure is the best) includes a singleton ApiClient
class that gets initialized on the AppDelegate
. Something like this:
// Inside AppDelegate#application:didFinishLaunchingWithOptions
ApiClientFactory.make();
// Inside ApiClientFactory
static func make() {
ApiClient.initialize(
userProvider: UserProvider(UserLocalRepo(), UserRemoteRepo()),
booksProvider: BooksProvider(BookLocalRepo(), BookRemoteRepo()),
...
)
}
The idea was to inject into the *Provider
s classes, mock repos when testing. But due to the way VCs
are instantiated I'm not sure this is a good design at all, and I'm not sure where would I inject those mock repo, as it seems AppDelegate#application:didFinishLaunchingWithOptions
still runs on tests (which means ApiClient
will be initialized with the actual classes, not the mock ones)