Unit testing an app based on Combine
I must confess that the topic of this recipe is very close to my heart: unit testing an app based on Combine.
We are going to implement an app that retrieves a list of GitHub users and shows them in a list view.
The code is pretty similar to the one in the Fetching remote data using Combine and visualizing it in SwiftUI recipe. But in this case, we'll learn how to unit test it – something that, even if it is very important, isn't well covered in documentation and tutorials.
Getting ready
Let's open Xcode and create a SwiftUI app called GithubUsers
, paying attention to enabling the tests by checking the Include Tests check box:
Then, add the githubUsers.json
file to the GithubUsersTests
folder. You can find it in this book's GitHub repository at https://github.com/PacktPublishing/SwiftUI-Cookbook-2nd-Edition-/blob/main...