swift - API 测试中对成员的模糊引用
问题描述
我正在努力学习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.dataTask(with: request) { (data, response, error) in
if error == nil {
XCTFail("Fail")
}
expectation.fulfill() //I got an error here
}
self.waitForExpectations(timeout: 20)
}
但我收到了这个错误:
在行中对成员“期望(描述:)”的模糊引用
expectation.fulfill()
谁能帮我看看我的问题在哪里?非常感谢
解决方案
推荐阅读
- php - 如何将数据从数据库 Laravel 传递到父布局
- node.js - 贝宝订阅和计费协议之间的区别?
- amazon-web-services - Lambda 未触发 SNS
- r - 在 as.POSIXct 中更改时区
- c++ - Maybe 和 Either 单子、短路和性能
- python - AttributeError:“int”对象没有属性“to_dict”
- arkit - generateCollisionShapes() 似乎不起作用
- c++ - 无论我运行同一个应用程序多少次,应用程序(.exe)中的函数都应该只调用一次
- linux - 将字符串添加到 awk 命令的末尾
- c++ - 函数返回错误的结果。查找 n 阶乘的最后一个非零数字