Unit testing not only is quite usefull to make my code better but I also really like the visual feedback in the form of the junit generated html reports. The reports automatically generated by the Ant build script provide a nice overview what test cases work or don’t work. More important, it shows me what I might have broken by adding a feature. The console results are just fine during development, the HTML reports are better suitable for publishing on the web for example.
These html reports are generated based on xml output from junit. This is all easy in an Ant based java project where tests are run using junit.
The problem is I mainly develop in Objective-C in which case I test using the OCUnit framework. The OCUnit framework nicely integrates with Xcode and displays failures the way Xcode displays compile errors. This is nice during development but pretty useless when builds are run automated on a remote machine.
So to publish test results from an automated xcode build I wrote a ruby script that transforms the console output from OCUnit to a junit compatible XML format. See the following Ant target how this works:
The first exec task executes the OCUnit target called Test and saves the result in the xcodebuild.out property. The second exec task transforms this output to xml using the OCUnitReport script. Finally a junitreport task is used to transform this xml to a html report in the reports/html directory.
Why use Ant to build a Xcode project? For one, the only way for the automated build tool CruiseControl to build a Xcode project is to wrap the the command line tool xcodebuild
in an exec
task. Ant also contains a lot of useful build-in tasks like ftp which can be used for example to upload the build reports to an external server.
Download (ruby script, 3kb)
It would be nice to include:
* Failure message from the test case.
* Execution time.
* Execution host.
* Timestamp.