I've got a Swift function for which Xcode is showing 0 passes in code coverage. The line is a closing brace (highlighted in red below). Is this a bug in Xcode? If not, what condition do I need to hit to run that line? I thought I was covering all paths through this method. The Xcode version is 8.3.3.
code coverage issue with brace
You can post images, but we cannot see them !!!
I have added an image there.🙂 But it seems that it isn't shown in the comment.
My Method is bellow. The last two braces were shown red. It means the two lines weren't excuted. Do you have a method to solve this?
func appointmentDisplayTitle()->String {
if (providerName.characters.count > 0 && facilityName != nil) {
return "\(providerName) at \(facilityName!)"
} else if (facilityName != nil) {
return facilityName!
} else {
return providerName
}
}
I have found a similar question in the stackoverflow. Maybe you can see in there.
May be you are missing a general catch statement, for all cases where the error is not createDirError.
But there is no try-catch in my codes. It is just if-else. It is weird that not all if-else show like this.
Could you try adding a dummy statement between the last 2 braces ?
func appointmentDisplayTitle()->String {
if (providerName.characters.count > 0 && facilityName != nil) {
return "\(providerName) at \(facilityName!)"
} else if (facilityName != nil) {
return facilityName!
} else {
return providerName
}
print("dummy statement")
}
I guess code coverage will outline the print.
That would mean that code coverage is a bit confused and considers the part between 2 braces as a statement ! Same conclusion in SO.