UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Unit Testing of CloudKit Using Mock Objects

Forums > Swift

I'm pretty new to Swift and app development, but I do have some history of software engineering. And while working on Paul's excellent long form project, Ultimate Portfolio App, I kept hearing the distant call of the "test first" mantra of Test-driven development (TDD) (Extreme Programming, if you are old enough to recall ;-).

I started to dig into ways of testing CloudKit, and came up with more questions than answers - including this one, which I think was on the right track. The problem is, CloudKit doesn't make itself easy to test. The main interface to the API, CKContainer, has init methods that cannot be overridden or overloaded. So drop-in mocks are out of the question. But to make a long story shorter, I tried many paths to test CloudKit and came up with a framework that works well for me - and I hope that it will for you too.

I call it the MockCloudKitFramework - and its fully documented (using DocC) and tested (see the accompanying project called "MockCloudKitTestProject" in the same repository). Its available here. It doesn't mock every CloudKit functionality by any means. But it does mock enough functionality to make it quite useful. And the framework can be extended to add more CloudKit functional mocking, so please let me know what you think and if you have ideas to extend it.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.