var property: Type {
if condition {
return value1
} else {
return value2
}
}
I have unit tests covering the if and else parts, but SonarQube reports that there’s no coverage for the line that has only the closing curly bracket, which looks like a bug to me.
Could it be solved by not having the else and make return value2 the last line of code before the curly bracket?
I understand your frustration with this. I would be frustrated too. Unfortunately, at root this is a question of what your coverage engine reports. SonarQube is just reflecting what the report says. So whether there is a viable workaround in code (I think there is) I urge you to also take this up with with your coverage engine to fix the report.
And now on to the code. As you propose, I believe this change would “fix” your coverage report with the same output from the code (not that you should have to do this):
var property: Type {
if condition {
return value1
}
return value2
}