jeudi 24 septembre 2015

Doing asserts after measureBlock

Is there any reason not to do a measureBlock in a separate unit test from my asserts? If there isn't, then how can I do asserts on a variable that I initialize in the measureBlock? I am getting errors in my asserts that the variable is being used before initialized.

Here is my code:

func testShouldCreateNounFromUITextFields() {
    let mockName: UITextField = UITextField()
    let mockType: UITextField = UITextField()
    let mockYear: UITextField = UITextField()
    let mockArea: UITextField = UITextField()

    mockName.text = "Name"
    mockType.text = "Type"
    mockYear.text = "1986"
    mockArea.text = "Area"

    let noun : Noun
    self.measureBlock {
        let noun = Noun(name: mockName, type: mockType, year: mockYear, area: mockArea)
    }

    XCTAssert(noun.name == mockName.text!, "The noun.name:" + noun.name + " was not equal to expected value of " + mockName.text!)

    XCTAssert(noun.type == mockType.text!, "The noun.type:" + noun.type + " was not equal to expected value of " + mockType.text!)

    XCTAssert(String(noun.year) == mockYear.text!, "The noun.year:" + String(noun.year) + " was not equal to expected value of " + mockYear.text!)

    XCTAssert(noun.area == mockArea.text!, "The noun.area:" + noun.area + " was not equal to expected value of " + mockArea.text!)
}

Aucun commentaire:

Enregistrer un commentaire