Last active
October 27, 2017 22:15
-
-
Save arbo-hacker/2dbd5f59e9babb70e801f9ab7987d439 to your computer and use it in GitHub Desktop.
Como escribir una prueba unitaria para una funcion que usa Alamofire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getAllData(_ completion: @escaping (_ error: NSError?, _ json: String?) -> Void) { | |
Alamofire.request("https://api.arbo.com.ve/test_api/getalldata").validate().responseJSON { (response) in | |
do { | |
let json = JSON(data: response.data!) | |
completion(json) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
class TestsFail: XCTestCase { | |
func testGettingJSON() { | |
Request.sharedInstance.getAllData { (error, result) in | |
XCTAssertNil(error) | |
XCTAssertNotNil(result) | |
ex.fulfill() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
class TestsSuccess: XCTestCase { | |
func testGettingJSON() { | |
let ex = expectation(description: "Expecting a JSON data not nil") | |
Request.sharedInstance.getAllData { (error, result) in | |
XCTAssertNil(error) | |
XCTAssertNotNil(result) | |
ex.fulfill() | |
} | |
waitForExpectations(timeout: 10) { (error) in | |
if let error = error { | |
XCTFail("error: \(error)") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment