I want to view the code coverage by running gcovr on generated gcda files. Jenkins seems to put the generated gcda files in Users/../Library/developer/Xcode/DerivedData/../../../i386. I expect them to be in Users/Shared/Jenkins/workspace/../build/example.build/Debug-iphonesimulator/example.build/Objects-normal/i386
When i run my IOS project with XCode locally it does generate gcda files and i can view my coverage. Im running xcode 5 and all tests are created with XCTest.
I've set 'Generate Test Coverage Files=YES' and 'Instrument Program Flow=YES' for debug and release, basicly i have done everything according to this post
In Jenkins i use the xcode plugin to build. It has two build commands. The first one builds with the target "example" and configuration debug. The second Xcode build command builds with the target "ExampleTests", configuration debug, arguments" test -destination OS=7.0,name=”iPhone Retina (4-inch)” and a scheme . In the output i can see the test being run and the simulator starts on the building machnine.
It seems i have missed something maybe in the project setting or havent set something right in the jenkins job. Maybe something like TEST_AFTER_BUILD=YES only then for XCode5.
As you recognised the .gcda files are put in the "wrong" directory.
Do the following:
Paste this script into the script field:
echo "Creating derivedDataDirectory file"
echo "${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}" > ${PROJECT_DIR}/derivedDataDirectory
XCode setup
(This creates a file with the path to the derivedDataDirectory)
Go to your jenkins project, click on "Add build step" and select "Execute shell".
Paste this script into the "Command" field:
#CopyCodeCoverageFile
echo "Start copying code coverage Files"
projectname="[YOUR PROJECTNAME]"
source=$(cat ${WORKSPACE}/$projectname/derivedDataDirectory)
cp -a $source/. ${WORKSPACE}/$projectname/
#CodeCoverage
echo "Start CodeCoverage"
cd ${WORKSPACE}/$projectname
[YOUR PATH TO GCOVR]/gcovr -r /private/tmp/workspace/${JOB_NAME}/$projectname --xml > ${WORKSPACE}/$projectname/test-reports/coverage.xml
Insert [YOUR PROJECTNAME] and [YOUR PATH TO GCOVR]. If your PROJECTNAME or target has spaces in it, this will cause trouble! Make sure all the paths are correct!
Tell me if something is not working for you or you found a better solution!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With