Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
In the previous part, we have already know how to set up the unit testing in Xcode project & some basic functionality.
Refer: https://mobikul.com/unit-testing-in-ios-using-swift-part-1/
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.
Example:
Here are Some Steps you need to follow this
here we have taken the example through “URLSession”
Valid URL: https://itunes.apple.com/search?media=music&entity=song&term=abba
here we are checking the URL response is valid or not.
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.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.