I have a project where I'm sending .GET requests to get data from the server and for this I'm using Alamofire & SwiftyJSON.
For example:
I have file "Links", "Requests" and my ViewController.
Links.swift
var getAllData: String {
return "\(host)api/getalldata"
}
Requests.swift
func getAllData(_ completion:@escaping (_ json: JSON?) -> Void) {
Alamofire.request(Links.sharedInstance.getAllData).validate().responseJSON { (response) in
do {
let json = JSON(data: response.data!)
completion(json)
}
}
}
ViewController
Requests.sharedInstance.getAllData { (json) in
// ...
}
So, how can I write my Unit Test for this case? I'm just now learning unit testing and in all books there are just local cases and no examples with network cases. Can anyone, please, describe me and help how to write Unit Tests for network requests with Alamofire and SwiftyJSON?