Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why this line is not covered? Xcode code coverage

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

enter image description here

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.

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

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

The entire project is available here.

EDIT: Adding code:

Test.swift

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

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
}
like image 890
DanielZanchi Avatar asked Mar 20 '19 09:03

DanielZanchi


People also ask

How do I enable code coverage in Xcode?

Running Tests and Coverage Locally in Xcode To enable code coverage, click the scheme editor in the toolbar. Select the CodecovDemo scheme and choose Edit Scheme. Select the Test action on the left. Check the Code Coverage box to gather coverage data.

How do I show test coverage in Xcode?

To view the coverage reports: Select the Report Navigator in the navigator pane on the left (⌘8) Select the latest Test run in the navigator pane. Select the Coverage tab in the editor.

How do you cover code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

Where is code coverage Xcode?

To view code coverage, select the Coverage tab. Xcode will display the overall code coverage for the framework, and we can expand this to get coverage data on individual files and functions.


1 Answers

Actually its a bug reported here.

  1. Coverage number varies between multiple runs on XC 10 on the same binary. Like in first run it shows x% vs in another run it will show y% keeping the same code.
  2. Coverage number/Number of tests varies while running on 11.4 simulator and 12.0 simulator, both ran on XC 10
  3. Number of tests also a little different like in some run it was 5507 tests vs in some runs it was 5506.

XC 10 certainly came with lots of bugs.

like image 52
youpilat13 Avatar answered Oct 19 '22 06:10

youpilat13