为什么不覆盖此行? Xcode代码覆盖率 [英] Why this line is not covered? Xcode code coverage

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

问题描述

我在Xcode的代码覆盖率报告中遇到问题。
正如您从此屏幕截图中所见:

I'm experiencing an issue with the report of code coverage in Xcode. As you can see from this screenshot:

在左边的选项卡上,从断点触碰了第58行,在右边的选项卡上,测试通过了。在右侧选项卡上,我仅在第37行运行测试。

On the left tab, line 58 is "touched" from the break-point, and on the right tab, the test passes. While on the right tab, I'm running only the test on line 37.

为什么Xcode将第58行标记为红色(未覆盖)?

Why does Xcode sign the line 58 in red, as not covered?

第53行未触及(如果我在此处设置了断点)。
使用SQLite作为数据库。

Line 53 is not "touched" (if I set a break-point there). Using SQLite as a database.

整个项目都可用此处

编辑:添加代码:

Test.swift

Test.swift

func testAddFuelFail() {
  fuelsManager.dropTable()
  XCTAssertEqual(addFuel(), -1)
}

FuelsManager.swift

FuelsManager.swift

func addFuel(dateOfFuel: Date, mileageOnSave: Int, quantityOfFuel: Double, pricePerUnitOfFuel: Double) -> Int64 {
  let insertFuel = fuelsTable.insert(date <- dateOfFuel, mileage <- mileageOnSave, quantity <- quantityOfFuel, pricePerUnit <- pricePerUnitOfFuel)
  do {
    let id = try database!.run(insertFuel)
      return id
  } catch {
    print(error)
  }
  return -1
}


推荐答案

实际上是报告此处



  1. 在同一二进制文件上XC 10上的多次运行之间,覆盖范围号有所不同。就像在第一次运行中显示x%,而在第二次运行中它将显示y%保持相同的代码。

  2. 覆盖率数/测试数在11.4仿真器和12.0仿真器上运行时会有所不同在XC 10上运行

  3. 测试次数也有所不同,例如在某些运行中为5507次测试,而在某些运行中为5506次。


XC 10肯定有很多错误。

XC 10 certainly came with lots of bugs.

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

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