Last active
November 28, 2023 15:47
-
-
Save lucianoschillagi/b2923bb937dd490e90094cec0fb2c775 to your computer and use it in GitHub Desktop.
Asynchronous Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import XCTest | |
| final class AsyncTests: XCTestCase { | |
| func testDownloadWebDataWithConcurrency() async { | |
| // Create a URL for a webpage to download. | |
| let url = URL(string: "https://apple.com")! // test passed! :) | |
| // let url = URL(string: "https://applexfsda.com")! // test don't passed :( | |
| // Use an asynchronous function to download the webpage. | |
| let dataAndResponse: (data: Data, response: URLResponse) = try await URLSession.shared.data(from: url, delegate: nil) | |
| // Assert that the actual response matches the expected response. | |
| let httpResponse = try XCTUnwrap(dataAndResponse.response as? HTTPURLResponse, "Expected an HTTPURLResponse.") | |
| XCTAssertEqual(httpResponse.statusCode, 200, "Expected a 200 OK response.") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment