Xcode 9.3
Seeing a very odd issue with code coverage. I have two unit tests which ultimately test every branch in the following init function (put breakpoints to double-check that). Yet code coverage is putting red in the gutter along with a zero next to the lines in the if-blocks.
Build is debug and code coverage turned on. I have not seeing the issue in other classes.
init(data aData: Data?) { // Function called 482 times during full unit test run
index = 0
let theLength : Int
if let theData = aData {
theLength = theData.count // Code coverage shows zero here and zone is colored red
data = theData
} else { // Code coverage shows 482 here (which cannot be since the if-block is reached 90%+)
theLength = 0
data = Data()
}
length = theLength
}
Same exact thing happens for a simple test class. Unit test created two instances, one passing in a 2, the other 3. Breakpoints prove both are hit, yet code coverage not reflecting that:
class IIFoo {
let s : String
init(x anX: Int) { // Code coverage shows 2 here
if anX % 2 == 0 {
s = "even" // Shows 0 here and zone is colored red
} else { // Shows 2 here, zone is red and shows some diagonal lines in the coverage count area.
s = "odd"
}
}
}