I am using Apollo SDK, which generates an API.swift file. Can we exclude this file from the code coverage
-
Short answer: no, you can only exclude target. But you can get creative: put that file in its own target, or move it to test target for tests (test target is typically excluded from coverage) – timbre timbre Mar 13 '22 at 20:06
3 Answers
You can't exclude files from code coverage report directly in Xcode. You can use external tools like xcov or slather to generate HTML version of report and set list of excluded files in its config file.

- 68
- 6
-
I can't make xcov read excluded files, there are several issues reported in github. I am not sure xcov is the solution at the moment – Riddik May 24 '23 at 07:55
You can do it in codecov.yml (external tools)
... ... ...
ignore:
- "path-for-file-to-ignore"

- 209
- 3
- 6
you can use the built in one llvm-cov
and you can specify it with the --ignore-filename-regex
parameter.
here is an example (and a demo project):
https://github.com/michaelhenry/swifty-code-coverage
with the coverage that you get from llvm-cov, you can have the option to display it in the stdout or a file or just push it somewhere like codecov or codeclimate
here is the file to be exact
https://github.com/michaelhenry/swifty-code-coverage/blob/main/lcov.sh
so you can either report
, export
or both the code coverage.
$ xcrun llvm-cov export --help
Cheers,

- 644
- 9
- 12