lundi 4 janvier 2016

XCTest for test model objects

Bellow i have mentioned my model object.

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
        }
    }
}

then i implemented a test case to check variables. Bellow i have mentioned the test case.

func testNetworkModelObject() {

    let connectionObject = ["network": ["first_name": "Dimuth", "last_name": "Lasantha", "business_email": "example@gmail.com", "currency": "USD", "language": "en-us", "category": "individual"]]
    let modelObject = HVConnection(data: connectionObject)

    XCTAssertEqual(modelObject.last_name, "Lasantha")
}

bellow i have mentioned the error

XCTAssertEqual failed: ("nil") is not equal to ("Optional("Lasantha")")

please help me to fix the issue

Aucun commentaire:

Enregistrer un commentaire