Swift API测试中对成员的引用不明确
我正在努力学习单元测试。为此,我想测试来自API的响应。 这是我的密码Swift API测试中对成员的引用不明确,swift,rest,unit-testing,Swift,Rest,Unit Testing,我正在努力学习单元测试。为此,我想测试来自API的响应。 这是我的密码 func testAPIworking(){ guard let url = URL(string: profileUrlstring) else {fatalError()} var request = URLRequest(url: url) request.httpMethod = "GET" let task = URLSession.shared.d
func testAPIworking(){
guard let url = URL(string: profileUrlstring) else {fatalError()}
var request = URLRequest(url: url)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if error == nil {
XCTFail("Fail")
}
expectation.fulfill() //I got an error here
}
self.waitForExpectations(timeout: 20)
}
但我有一个错误:
对成员“期望(说明:)”的引用不明确
按照
有人能帮我解决我的问题吗?
非常感谢有任何帮助吗?我需要您的帮助。您的容器类是否继承自XCTestCase()?您是否声明让期望值=期望值()
expectation.fulfill()