Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 code coverage reporting not working

Tags:

xcode

ios

llvm

I'm having problems to get code coverage reporting working in Xcode 7 for a certain iOS project.

I'm following the instructions given here: http://mgrebenets.github.io/mobile%20ci/2015/09/21/code-coverage-for-ios-xcode-7/

Of the three projects I tried, two are working fine, but one project is giving me a headache. When using llvm-cov utility to generate a report from the gathered profile data like this:

xcrun llvm-cov report -instr-profile Coverage.profdata MyAppBinary 

I receive the error message:

error: Failed to load coverage: The file was not recognized as a valid object file

I checked that the "Gather coverage data" is enabled for the Test scheme. I also checked that the -fprofile-instr-generate and -fcoverage-mapping compiler options are passed to clang.

File sizes and types also look valid to me:

ilMac:llvm-cov-test ilja$ ls -la
total 61976
drwxr-xr-x   4 ilja  staff       136 14 Okt 21:53 .
drwxr-xr-x+ 75 ilja  staff      2550 14 Okt 16:31 ..
-rw-r--r--   1 ilja  staff   1797416 14 Okt 21:53 Coverage.profdata
-rwxr-xr-x   1 ilja  staff  29932040 14 Okt 16:32 MyAppBinary

ilMac:llvm-cov-test ilja$ file Coverage.profdata 
Coverage.profdata: data

ilMac:llvm-cov-test ilja$ file MyAppBinary 
MyAppBinary: Mach-O universal binary with 2 architectures
MyAppBinary (for architecture i386):    Mach-O executable i386
MyAppBinary (for architecture x86_64):  Mach-O 64-bit executable x86_64

I also noted that the "Coverage" tab in Xcode for the Test run is saying "No coverage data" instead of the indicator bars.

Any idea what I'm doing wrong?

like image 938
iljawascoding Avatar asked Jul 01 '26 16:07

iljawascoding


1 Answers

Posting my solution in case someone will need it. Following this article code coverage xcode 7 I did following steps:

  1. Installed cobertura plugin
  2. Installed slather plugin
  3. Enabled code coverage for project (in schema preferences)
  4. In jenkins added execute shell command

/usr/bin/xcodebuild test -workspace MyApp.xcworkspace -scheme MyAppTests -configuration DebugMyApp -destination "platform=iOS Simulator,OS=9.3,name=iPhone 6" -enableCodeCoverage YES

  1. Then one more build stem for slather

slather coverage \ --input-format profdata \ --cobertura-xml \ --ignore "../**/*/Xcode*" \ --output-directory slather-report \ --scheme MyAppTests \ --workspace MyApp.xcworkspace \ MyApp.xcodeproj

  1. And last but no least add post build step "publich cobertura report" Cobertura xml report pattern - slather-report/cobertura.xml
  2. Enjoy :)
like image 57
Roma Avatar answered Jul 04 '26 04:07

Roma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!