为什么右花括号没有显示代码覆盖率? [英] Why is a closing brace showing no code coverage?

查看:174
本文介绍了为什么右花括号没有显示代码覆盖率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Swift函数,其Xcode在代码覆盖率中显示了0次传递。该行是一个大括号(下面用红色突出显示)。

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).

这是Xcode中的错误吗?如果不是,我需要打什么条件才能运行那条线?我以为我已经涵盖了通过此方法的所有路径。

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.

推荐答案

请确保这是Xcode代码覆盖率的错误(功能?)。问题归结为return语句,不允许它归结为空的else语句,因此指示代码未执行。 return语句使他们无法计算代码行数。

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.

在try / catch块的实例中,实际上并没有太多东西

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

作为一个实验,删除return语句并找到一种更好的方法来捕获writeToURL语句,这样它就不会在错误中执行/ catch语句。这样可能会为您提供该行的原始代码覆盖范围。

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.

这篇关于为什么右花括号没有显示代码覆盖率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆