Xcode 使用ObjectMapper进行Swift模型单元测试
在解析JSON以构建对象时,我有一组使用ObjectMapper库的模型。 如何为我的模型编写单元测试?我对这一点还相当陌生,到目前为止,我读到的东西让我相当困惑。 下面是我的一个模型的示例: 也许可以试试这个:Xcode 使用ObjectMapper进行Swift模型单元测试,xcode,swift,unit-testing,model,xctest,Xcode,Swift,Unit Testing,Model,Xctest,在解析JSON以构建对象时,我有一组使用ObjectMapper库的模型。 如何为我的模型编写单元测试?我对这一点还相当陌生,到目前为止,我读到的东西让我相当困惑。 下面是我的一个模型的示例: 也许可以试试这个: import XCTest import ObjectMapper @testable import AppName class User Tests: XCTestCase { func testMapsData() { let jsonDictionar
import XCTest
import ObjectMapper
@testable import AppName
class User Tests: XCTestCase {
func testMapsData() {
let jsonDictionary: [String: Any] = ["id": 10, "firstName": "John", "lastName": "Doe"]
let user = Mapper<User>().map(JSON: jsonDictionary)
XCTAssertEqual(user?.id, 10)
XCTAssertEqual(user?.firstName, "John")
XCTAssertEqual(user?.lastName, "Doe")
}
}
import XCTest
import ObjectMapper
@testable import AppName
class User Tests: XCTestCase {
func testMapsData() {
let jsonDictionary: [String: Any] = ["id": 10, "firstName": "John", "lastName": "Doe"]
let user = Mapper<User>().map(JSON: jsonDictionary)
XCTAssertEqual(user?.id, 10)
XCTAssertEqual(user?.firstName, "John")
XCTAssertEqual(user?.lastName, "Doe")
}
}