Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding code from coverage stats in Xcode 7

I have enabled code coverage statistics in Xcode 7.0 and Objective C (like this) and it's working well.

Is it possible to mark some source lines so that they are ignored by the coverage report? If I was using lcov then I could use LCOV_EXCL_START and LCOV_EXCL_END markers (as in How to tell lcov to ignore lines in the source files) but Xcode doesn't recognize those.

Does Xcode have an alternative mechanism for doing this?

like image 245
Ewan Mellor Avatar asked Sep 22 '15 01:09

Ewan Mellor


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. To include assemblies that aren't part of your solution, obtain the . pdb files for these assemblies and copy them into the same folder as the assembly .

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 I show Test coverage in Xcode?

Enabling Code Coverage in Xcode Code coverage is enabled in the scheme editor. Click the Covered scheme and choose Edit Scheme.... Select Test on the left and check the checkbox Gather coverage data. That is it.

How do you set 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.


1 Answers

Xcode7 and later (based on some forum posts), the coverage system uses LLVM's coverage generation and reporting mechanisms, the format for which is detailed at http://llvm.org/docs/CoverageMappingFormat.html. As of Xcode 9, this format does not support any means of exclusion of lines (or other structures).

The resulting mapping is exported into a consumable format (txt or html) by llvm-cov, which also doesn't really have much in the way of exclusion mechanisms. llvm-cov does have some simple thresholding for only reporting on "greater than" or "less than" coverage for both lines and regions, but I suspect that's not entirely what you're after based on the question above.

like image 90
heckj Avatar answered Nov 12 '22 04:11

heckj