0
貝婁我提到了我的模型對象。XCTest for test model objects
class HVConnection: NSObject {
//private var _data: NSMutableDictionary
private var _data: NSMutableDictionary
// MARK:- Init
init(data: NSDictionary)
{
_data = NSMutableDictionary(dictionary: data)
}
// MARK:- Properties
var last_name: String? {
if let lastNameObject = _data.objectForKey("last_name") {
return (idObject as! String)
} else {
return nil
}
}
}
然後我實現了一個測試用例來檢查變量。 貝婁我提到了測試案例。
func testNetworkModelObject() {
let connectionObject = ["network": ["first_name": "Dimuth", "last_name": "Lasantha", "business_email": "[email protected]", "currency": "USD", "language": "en-us", "category": "individual"]]
let modelObject = HVConnection(data: connectionObject)
XCTAssertEqual(modelObject.last_name, "Lasantha")
}
波紋管我剛纔提到的錯誤
XCTAssertEqual失敗:( 「無」),不等於( 「可選(」 Lasantha 「)」)
請幫我解決問題
當你創建modelObject,並且你做'modelObject.last_name'它是否返回正確的值?我想也許你傳遞的字典只有一個關鍵/價值與「網絡」 –