我有一個帶有計算變量的模型對象。現在我想測試變量的setter。我寫了一個測試案例,它提供了以下錯誤XCTest用於模型對象中的測試設置器
XCTAssertEqual失敗:( 「無」),不等於( 「可選(」 [email protected] 「)」) -
波紋管我已經提到,我寫了
func testNetworkModelObjectSet() {
let testObject = ["network": ["first_name": "Dimuth", "last_name": "Lasantha", "business_email": "[email protected]", "currency": "USD", "language": "en-us", "category": "individual"]]
let network = HVConnection(data: testObject)
network.business_email = "[email protected]"
XCTAssertEqual(network.business_email, "[email protected]")
}
這裏我提到變量相關的模型對象的測試用例
class HVConnection: NSObject {
//private var _data: NSMutableDictionary
private var _data: NSMutableDictionary
// MARK:- Init
init(data: NSDictionary)
{
_data = NSMutableDictionary(dictionary: data)
}
var business_email: String? {
get {
if let businessemailObject = _data.objectForKey("network")?.objectForKey("business_email") {
return (businessemailObject as! String)
} else {
return nil
}
}
set {
_data = ["business_email": newValue!]
}
}
}
你應該使用'XCTAssertEqualObjects'爲對象,'XCTAssertEqual'是原始類型,如'int','字符','double'等。 – rckoenes
@rckoenes Swift的'XCTest'沒有'XCTAssertEqualObjects'。 – Cristik
@Cristik你是對的,切換到兩者之間。 – rckoenes