Saturday, 30 June 2012

XCode 4.3 and Jenkins Code Test Coverage Updated

Since I wrote this post, XCode has been updated somewhat, more concise xcodebuild commands can be found here:

Another trip to the US under my belt.  That makes five trips in the last twelve months.  The only thing I'll say on the matter is that flying to and from JFK-LHR is so much easier than flying PDX-SEATAC-LHR.  Five and a half hours on the way back is just a ridiculous fast flight time to get thousands of miles across the Atlantic.  That coupled with Silver BA Executive Club, almost guaranteed upgrades to Club on at least one leg of each flight makes the whole business almost bearable.  The only problem, of course, is that if the ride's bumpy it's bumpy for everyone from Cattle to First.


So, XCode 4.3 makes the generation of code coverage files so much easier and this updates my previous post on the topic.  Specifically, this is geared towards doing CI builds of XCode projects from the command line.


1. Make sure you have a Test target set up in your project
2. Select it from your project settings TARGETS list
3. Go "Build Settings"
4. Set "Generate Test Coverage Files" and "Instrument Program Flow" to "Yes"

5. Optional - I don't use the "Test After Build" project setting in my main project targe to trigger the tests as I only want code coverage running on my central CI due to my desire to integrate exclusively with Cobertura.
Make sure that your CI build has the following command/s in it:

# Build and test
xcodebuild -sdk iphonesimulator -project MyProject.xcodeproj -target MyProjectTests -configuration Debug clean build TEST_AFTER_BUILD=YES

# Generate code coverage report.
/path/to/gcovr -r $ROOT --exclude '.*Developer.*' --exclude '.*MyProjectTests.*' --xml > MyProject/coverage.xml

The final bit is my hook in for GCOVR to generate Cobertura reports.