Exclude a swift file from XCode code coverage
Asked Answered
H

3

6

I am using Apollo SDK, which generates an API.swift file. Can we exclude this file from the code coverage

Hued answered 13/3, 2022 at 1:41 Comment(1)
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)Morra
M
2

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.

Mcdonnell answered 14/3, 2022 at 11:24 Comment(1)
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 momentMezereon
C
0

You can do it in codecov.yml (external tools)

... ... ...

ignore:

  • "path-for-file-to-ignore"
Capsize answered 15/9, 2022 at 9:17 Comment(0)
L
0

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

enter image description here

Cheers,

Luteal answered 20/10, 2022 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.