Testable network calls Swift
You can refactor this method (and downloadLatestFileAWS, too), to take an optional completion handler parameter:

func requestDownloadLinkForAWS(completion: @escaping ((Result&lt;URL, Error&gt;) -&gt; Void)? = nil) {
    ...

    do {
        ...
        downloadLatestFileAWS(dataResponse.bucketName, dataResponse.folderName, dataResponse.version, completion: completion)
    } catch let error {
        completion?(.failure(error))
    }
}

func downloadLatestFileAWS(_ bucket: String, _ folder: String, _ version, completion: @escaping ((Result&lt;URL, Error&gt;) -&gt; Void)? = nil) {
    ...
    completion?(.success(url)) // the file URL of the saved file
}


Then you can test it:

func testDownload() {
    var result: String?

    let expectation = self.expectation(description: "download")
    requestDownloadLinkForAWS { result in
        if case .failure(_) = result {
            XCTFail("Download failed")
        }
        expectation.fulfill()
    }
    wait(for: [expectation], timeout: 10)
}


By the way, by adding a completion handler to the download method, it also offers you the opportunity to have the caller specify what UI updates should take place when the download is done. For example, you generally don’t want to bury those UI updates within downloadLatestFileAWS. Also, rather than just printing the error to the Xcode console, the caller can now specify what it wants to do when an error occurs.

That having been said, you might not want to actually perform network requests in unit tests. You might, instead mock the network service, or use URLProtocol to mock it behind the scenes.

But either way, you can make your methods testable by providing them with completion handler closures.