32

How would you exclude a few methods, or say the AppDelegate file, from being tested during Code Coverage in Xcode 7?

I am not using Gcov.

Mark
  • 7,167
  • 4
  • 44
  • 68
MainakChoudhury
  • 502
  • 1
  • 7
  • 23

1 Answers1

15

Xcode coverage is generated by target (you can enabled it per scheme). Something I often do is separate all my testable code into a separate DynamicFramework from all my UI code. I can generate coverage just for that one framework if i like.
enter image description here

Alternatively you could look at some of the 3rd party coverage parsing tools such as:

Each tool will generate you a set of coverage metrics (based on the coverage data generated by Xcode) and they have the ability to exclude specific files from the coverage generation.

Xcov

--ignore_file_path -x: Relative or absolute path to the file containing the list of ignored files.

Slather

# .slather.yml
ignore:
 - ExamplePodCode/*
 - ProjectTestsGroup/*

Personally I find that xcov is nicer to look at but slather is slightly more detailed

Community
  • 1
  • 1
Jeef
  • 26,861
  • 21
  • 78
  • 156
  • 1
    Unfortunately, xcov doesn't respect the ignore files when calculating total coverage: https://github.com/nakiostudio/xcov/issues/130 – ackerman91 Aug 29 '18 at 18:19
  • 3
    I have some Guard statements in the code, for safe programming, which should never be invoked. Code coverage says my code never reaches these locations, thus is not 100%. Is there anyway to correct this using some inline macro? – Steve Sheets Apr 12 '19 at 21:16