Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Files/Lines of code in Xcode 7 Code Coverage

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.

like image 298
MainakChoudhury Avatar asked Nov 24 '15 07:11

MainakChoudhury


People also ask

How do you exclude files from code coverage?

To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to your test class.

How does Xcode measure code coverage?

To measure and visualize code coverage for a project, follow these steps: Enable code coverage date gathering. To do this, go to Product › Scheme › Edit Scheme... , and select Test from the left hand side menu. Under the Info section, check the Gather coverage data box.

How do you exclude from code coverage Junit?

Edit Configurations > Select Code Coverage tab > then adding the package or class I want to be excluded or include only in the code coverage report.


1 Answers

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:

  • xcov
  • slather

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

like image 153
Jeef Avatar answered Sep 22 '22 23:09

Jeef