jeudi 25 août 2016

Best way to perform the same unit test with different values

I have a simple test (see below). I would like to run the test with like 6 input values. I could create 6 single methods with 6 datasets, or iterate through 6 setups. While putting everything in it's own method would show me a failure more detailed, the second one would have less redundant code.

Which way is the better one?

    func testValueByStringRange_1(){

    let parser = Parser()
    let input = "22016080120160802ZE0000000000000+RP0000000000000+RF0000000000000-"
    let indexFrom = 19
    let indexTo = 31

    let expected = "000000000000"
    let returnString = parser.valueByStringRange(input, indexFrom: indexFrom, indexTo: indexTo)

    XCTAssertEqual(returnString, expected)
}

Aucun commentaire:

Enregistrer un commentaire