Xcode: Unit Testing Built Products

Just wanted to share a little trick I recently developed for Xcode. I had a problem with FlickrExport 3: the Info.plist file was not being regenerated correctly when I built the target without cleaning it first. This problem only came to light when I started using preprocessing in the Info.plist to fill in the CFBundleVersion from a build setting defined in a .xcconfig file. The result was that I thought I was building version 3.0.0bX and the final product's Info.plist was actually 3.0.0b(X-1).

What I wanted to do was to check that everything was copacetic in the built product after the build was finished. My solution was to add a final Shell Script build phase to the target with the following code:

grep -q "${FE_APERTURE_VERSION}" \
if [ $? -eq 0 ]; then
echo "Plist check passed."
echo "Error: out of date plist in built product. Perform a clean build."
exit 1

This fragment greps the built Info.plist file for the current value of the FE_APERTURE_VERSION build setting. If they don't match, the script exits with a non-zero code and Xcode stops the build.

I've since expanded this a bit to check that the included frameworks are in their proper locations, are correctly built as Universal Binaries and so on.