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 see 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 GithubUsersApp
, paying attention to enabling the Unit Tests:
Then, add the githubUsers.json
file to the GithubUsersAppTests
folder. You can find it in the GitHub repository at https://github.com/PacktPublishing/SwiftUI-Cookbook/blob/master/Resources/Chapter09/recipe6/githubUsers.json: