Showing posts with label xcode. Show all posts
Showing posts with label xcode. Show all posts

Saturday, April 07, 2007

OCUnit test reports

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:

<target name="test" depends="build"
description="Builds the project, runs the unit tests, generates a report">

<exec executable="xcodebuild" dir="zip-framework" failonerror="false" outputproperty="xcodebuild.out">
<arg line="-target Test -configuration release build" />
</exec>

<mkdir dir="reports" />
<mkdir dir="reports/raw" />
<exec executable="OCUnitReport" errorproperty="report-error.out" inputstring="${xcodebuild.out}" searchpath="true" resolveexecutable="true">
<arg line="-d reports/raw" />
</exec>
<echo message="${report-error.out}" />

<mkdir dir="reports/html" />
<junitreport todir="reports">
<fileset dir="reports/raw">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="reports/html" />
</junitreport>
</target>


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, 5kb)

Tuesday, December 19, 2006

JKDistributedView

While trying to duplicate the RuleView used by Apple in the Finder for example I ran into the problem of resizing views. The RuleView needs to grow in size when a new rule is added. Each view following the RuleView needs to be resized to to create space for the RuleView. Since layout in InterfaceBuilder works using springs, but you can't attach two edges of view together, I created a helper view called JKDistributedView which helps me resize and reposition it's children views.



To use JKDistributedView you add a NSView subclass to Interface Builder and set it's custom class to JKDistributedView. Every nsview added to JKDistributedView will be layout according to the following rules:

  • top to bottom
  • Every view will get it's preferred height
  • When a views vertical springs are dynamic the view will fill all remaining vertical space after the fixed height views are sized.
When a rule is added to the JKRuleView it needs to grow in size. JKRuleView calls descendantFrameChanged: on it's parent view (JKDistributedView) to indicate all children of JKDistributedView need to be resized and repositioned.

So the finder smart folder view would be created using 3 views as subviews in a JKDistributedView. The JKRuleView, the NSOutlineView (using a dynamic vertical resize hint) and a third view at the bottom to display the path of the selected file. JKDistributedView makes sure the JKRuleView and the path view have a fixed size, the NSOutlineView will fill all space in between. Now when you click the add button in the JKRuleView a new rule will be added, JKDistributedView will increase JKRuleViews height and decrease the height of the NSOutlineView

Sunday, December 10, 2006

XCode todo list

One of the things I use in TextMate regularly is the apple-cmd-b key combo, to bring up a todo list for the current project. Whenever I have something planned in my code, but don't feel like implementing it yet I annotate this piece of code with a comment like:

// TODO: check if url exists before saving it
saveURL(url);
The todo plugin will list all these TODO's from my code which gives me an indication on how to improve my code further.

The problem is that while I use TextMate for my web and java programming, I use XCode for most of the real programming done using Objective-C/Cocoa. But XCode doesn't have the todo feature and there is no way to add plugin's to XCode. Even a google search resulted in nothing on the subject.

So for now I'm using the Lightweight issue tracking bash script I found which seems like the only solution usable in combination with XCode.

# grep for "TODO" string
todo()
{
if [ $# -lt 1 ]; then
grep -R -n "TODO: " . | grep -v ".svn"
else
# loop through the args
while [ -n "$1" ]
do
grep -R -n "TODO: " "$1" | grep -v ".svn"
shift
done
fi
}


Add this script to your ~/.bash_profile to be able to execute the todo command that searches the current directory, or the directories given as argument for // TODO: lines.