我一直在寻找如何修复这个错误,但没有成功。目前,我使用的是Xcode 14。我不知道这是否与这些错误有关。
基本上,当我尝试执行测试时,它们就会出现,所以不会编译项目。
These are the errors
Undefined symbol: :$s10SwiftyJSON0B0V17dictionaryLiteralACSS_yptd_tcfC
Undefined symbol: _$s10SwiftyJSON0B0VMn
我的代码
模拟(仅使用 createReport 函数):
import Foundation
@testable import PurchHist
import SwiftyJSON
struct JsonObject: Codable {
let subject: String
let detail: String
}
class MockErrorReport: ReportIssuesServiceProtocol {
var error: ErrorKind?
let json = JSON()
func createReport(withParams params: JSON, completion: @escaping ReportIssueResponse) {
completion(error, nil)
}
func uploadImage(uploadData: UploadData, completion: @escaping ReportIssueImageResponse) {
}
}
单元测试:
func testSendReport() {
let mock = MockErrorReport()
viewModel = .init(reportService: mock)
var capturedResult: Any?
var capturedError: Error?
let promise = expectation(description: "Completion handler has been invoked")
viewModel.reportService.createReport(withParams: mock.json, completion: { error, errors in
if error == nil && errors == nil {
capturedResult = true
} else {
capturedError = error
}
promise.fulfill()
})
waitForExpectations(timeout: 5)
XCTAssertEqual(capturedResult as! Bool, true)
XCTAssertNil(capturedError)
}
1条答案
按热度按时间nxagd54h1#
我遇到了同样的问题,问题是swiftyJSON库,您应该在podfile
的单元测试目标中安装该库。