1

尝试设置执行网络请求并尝试序列化响应的单元测试。我目前收到错误:Ambiguous reference to member 'jsonObject(with:options:)'. 对为什么会发生这种情况感到困惑,因为单元测试应该知道什么 JSONSerialization。是?

func testAccessKeys() {
    let expected = expectation(description: "Run the Access request")
    sut.request(.Access, data: nil) { finished, response in
        if response != nil && finished == true {
            guard let json = try? JSONSerialization.jsonObject(with: response!, options: .mutableContainers) as! [String:Any] else { return XCTFail("Access request was not a dictionary")}
            XCTAssertNotNil(json?["id"])
            expected.fulfill()
        } else {
            XCTFail("Access response was nil")
        }
    }
    waitForExpectations(timeout: 3) { error in
        if let error = error {
            XCTFail("Access request failure: \(error)")
        }
    }

}
4

1 回答 1

1

确保响应的类型为DataInputStream

如您在文档中所见,这些是此函数接受的唯一类型

于 2018-04-09T10:17:40.910 回答