In this blog, we will discuss how to test the Network Call (Asynchronous function).
In-Network call we have to wait until the data will come to its totally Asynchronous function so that we have to wait in method until the result will come for that swift provide “expectation”
With the help of this, we can handle Network call.
XCTAssertNil(responseError,"Any String Value")// it will pass when he get nil value nil == no issue
XCTAssertEqual(statusCode,200)// it compare the value if equal then no issue.
}
Here we have taken the “expectation” class to hold the network call response.
We have taken two Test checking method
1: XCTAssertNil(responseError,”Any String Value”) . if responseError returns nil then there is no issue.
2: XCTAssertEqual(statusCode, 200) if statusCode == 200 then no issue
if any matches fail then you will get the test fail result.
For checking the error case you just change the URL’s string or Invalid URL & check.
This Is The Introduction Of The Async Network Call & Some Other Tips To Test Valid URL , In next Blog we will talk about the Network request through Alamofire .
Expert in Swift, Objective-C and MVC architecture. Skilled in REST API integration, GraphQL, custom views, and performance optimization using Xcode Profiler and advanced development tools.
Be the first to comment.