Ios 如何在XCTest上测试Alamofire

Ios 如何在XCTest上测试Alamofire,ios,swift,alamofire,xctest,Ios,Swift,Alamofire,Xctest,我正在学习如何正确地单元测试我的方法。我有一个版本检查方法,可以从Web服务中检索JSON。我该怎么做呢 //check for new version, compare if the current version is older than server version func checkNewVersion() { request(URLRouter.CheckForUpdate()).responseJSON { responseDa

我正在学习如何正确地单元测试我的方法。我有一个版本检查方法,可以从Web服务中检索JSON。我该怎么做呢

 //check for new version, compare if the current version is older than server version
    func checkNewVersion() {

        request(URLRouter.CheckForUpdate()).responseJSON {
            responseData in
            if responseData.result.isFailure
            {
                let alertController =  self.setActionPrompt("Network Error", message: "Error in signing in to tasker service", buttonText: "Retry", openLiveLab: false)
                self.presentViewController(alertController, animated: true, completion: nil)
            }
            else
            {
                let j = JSON(data: responseData.data!)
                for (key,subJ) in j {
                    if key == kAppId
                    {
                        let serverVer = subJ["ver"].string!
                        let iosUrl = subJ["iosUrl"].string!
                        let ver = serverVer.compareVersion(kAppVer, ServerVer: serverVer) // compare if the current version is older than server version

                        if (ver) // if older
                        {
                            let alertController = self.setActionPromptWithURL("Update Available!",
                                message: "Please update APP to \nthe latest version \n\n Thank you!",
                                buttonText: "Update", url: iosUrl)
                            UIApplication.sharedApplication().keyWindow!.rootViewController!.presentViewController(alertController, animated: true, completion: nil)
                        }
                        else { self.loginServices() }
                    }
                }
            }
        }
    }

我使用Ohttpsubs测试alamofire:这是我测试NSURLSession的方式。还应与任何基于闭包的网络框架配合使用。