In this post, we shall see how protocols work with unit testing. Say, you have a downloader class DownloadFileClass for fetching network data. It follows the protocol DownloadFileProtocol. The whole class and protocol looks like this. protocol DownloadFileProtocol { func downloadFile(with name: String, completion: (String) -> ()) } class DownloadFileClass { var downloadedFile: