This is an excerpt from episode “Modern SwiftUI: Dependencies & Effects”.
You may have heard that “mocks are bad” and that they cause you to test the mock rather than your application’s actual feature. That doesn’t have to be the case. It is totally fine to mock a dependency to a system that you do not control, such as the file system. You do not need to test that saving and loading with that dependency works (after all, that’s the mocked behavior!), but you should test how your application behaves when it tries to load or save data. For example, is data saved after each change to your app’s data? Or, if loading data throws an error, do you show an alert to the user?
Our free plan includes 1 subscriber-only episode of your choice, access to 64 free episodes with transcripts and code samples, and weekly updates from our newsletter.