Why is a closing brace showing no code coverage?

一个人想着一个人 提交于 2020-01-01 02:29:30

问题


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.


回答1:


xcode reports include measurements for ending brackets, which is not typically desired. There is nothing you can do in configuration to fix this (as far as I know).

(FD I work at Codecov) You can use Codecov, a hosted solution, that will remove these extra lines automatically. Learn more at https://github.com/codecov/example-xcode. Thanks :)




回答2:


Pretty sure this is a bug (feature?) of Xcode code coverage. The issue boils down to the return statement not allowing it to fall down to the empty else statement, thus indicating the code is not executed. The return statements throw a wrench into whatever they are doing to count the lines of code.

In the instance of your try/catch block, you don't really have much choice there to prevent the empty execution.

As an experiment, remove the return statement and find a better way to catch the writeToURL statement so it doesn't execute in an error/catch statement. That will likely give you clean code coverage for that line.



来源:https://stackoverflow.com/questions/34622082/why-is-a-closing-brace-showing-no-code-coverage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!