Check Mobile App
Read now
Start a Project

Unit Testing in iOS using swift (Part 2)


Network Call Check

In the previous part, we have already know how to set up the unit testing in Xcode project & some basic functionality.


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.


Here are Some Steps you need to follow this

1: Set up Class.

here we have taken the example through  “URLSession”

2: Now Start writing the network class checking method.

Valid URL:

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.


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 .

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.


Very good company, we did get app extension for Magento 2 website. The support was very good they help us through the process. Webkul team is very supportive, I would recommend them.

Yasser Mohamed

Yasser Mohamed

Talk to Sales


Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home