Testing in iOS - Part 18: Code Coverage | Ray Wenderlich

Knowing what is tested and what is not, is as important as writing the tests. Thankfully, Xcode provides code coverage reports.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3530-testing-in-ios/lessons/18

In 5 minutes 13 seconds into the movie in the code coverage area you have stripes on the gutter. See also this question on SO: What is the meaning of rectangle areas with stripes, while having test coverage enabled in Xcode? - Stack Overflow

Why this area is covered in stripes (it is not red, nor green). What does this mean in Xcode?

@bdmoakley Do you have any feedback regarding this? Thank you - much appreciated! :]

Update: I realized after I did my checking and the last post that the final project does not have code coverage turned on. You get the stripes once you turn on code coverage, but not otherwise and if you notice the stripes are there for every XCTAssert statement. I had not seen this behaviour before but I believe that the striped lines are simply showing lines of code where only part of the code was executed.

If you hover over one of the striped lines, if the test passed, then the part where the condition is would be displayed in green while the error message (which shows only on failure) is shown in red. So these striped lines are for code coverage indicating partial coverage …

for XCode 9.3

  1. Choose Edit Scheme from the scheme menu in the toolbar.

  2. In the left column, select the Test scheme action.

  3. Click Options at the top of the right column.

  4. Click the “Gather coverage for” check box and set the popup to either “all targets” or “some targets.”

  5. Click Close.