How to use "enableCodeCoverage" flag For Xcode test step

Is there a way to use the new “enableCodeCoverage” from Xcode 8 for generating coverage files using llvm-cov instead of using gcov. I tried placing the flag in the “Additional options for xcodebuild build test call” section and setting the “Generate code coverage files?” to no, but when looking at the build logs, I don’t see it being used. Also is there a way to get the path of where the coverage log is store in derived data?

1 Like

Hi @eman6576,

Why do you think that? What’s the xcodebuild ... command in the build log? Can you please copy paste it?

I see this: $ env "NSUnbufferedIO=YES" xcodebuild "-workspace" "BaseAppV2.xcworkspace" "-scheme" "BaseAppV2" "test" "-destination" "platform=iOS Simulator,name=iPhone 6,OS=latest" "-enableCodeCoverage" "YES". But towards the end of the step, I don’t see an indication of the coverage report generated successfully or not. I do see this: ** TEST SUCCEEDED **

If you use the -enableCodeCoverage option the generated profile should be at $PROJECT_TEMP_ROOT/CodeCoverage/$PROJECT_NAME/Coverage.profdata - source:

You can run the same command locally on your Mac to test it, or with our CLI (How to debug your build locally / "It works on my Mac/PC but not on")

So it would be $BITRISE_PROJECT_PATH/CodeCoverage/BaseAppV2/Coverage.profdata?

Did you try to run the xcodebuild command locally, or use the CLI to run the build locally?

Yes, most likely, but depends on your Xcode project configs.

I tried it locally.

And where was the generated .profdata ?

Note: you can use the command line find to find files quickly: find . -name '*.profdata' to search in the current directory and the dirs below that.


Then doing ls I see Coverage.profdata Intermediates Products ProfileData. So think the path would be
$PROJECT_TEMP_ROOT/CodeCoverage then?

It can be, although it seems that you have some related custom (non default) options in your Xcode project, e.g. DerivedData by default shouldn’t be in the source code’s dir.

I think I have a setting of showing hidden directories locally.

DerivedData (by default) is not a hidden directory, but a directory outside of the source code dir (~/Library/Developer/Xcode/DerivedData)

In any case, I’d suggest you to run the build locally with the Bitrise CLI and check where the file is - it’ll be at the same location on too. E.g. relative to the repository root $BITRISE_SOURCE_DIR/rel/path/...

I tried something different. When running tests, I added this flag: -derivedDataPath ./out. Then I wrote a script that access the directory and prints the Coverage.profdata.

1 Like

Think the derived data in source directory has something to do with the issue i’m having. Is there a way not to have it in the source directory?

What’s the issue exactly? I thought you just needed the location of the code coverage data. Is there something else?

I was able to resolve the issue. Codecov came out with a new feature where you can get the report throught plist files instead. Sorry for the late response.

1 Like

Thanks for reporting @eman6576 - I’ll mark this as resolved