<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Julian Rex &#187; unit testing</title>
	<atom:link href="http://rexy.co.uk/tag/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://rexy.co.uk</link>
	<description>iPhone Game Developer</description>
	<lastBuildDate>Thu, 10 Dec 2009 04:31:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unit testing on the iPhone and the Simulator</title>
		<link>http://rexy.co.uk/2009/06/unit-testing-on-the-iphone-and-the-simulator/</link>
		<comments>http://rexy.co.uk/2009/06/unit-testing-on-the-iphone-and-the-simulator/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 03:03:51 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphonedev]]></category>
		<category><![CDATA[simulator]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://rexy.co.uk/?p=92</guid>
		<description><![CDATA[A recent post over on Acorn Heroes, &#8220;Unit Testing and linking Static Libraries with XCode&#8221;, has got me thinking: I went through a similar process a few months ago, when I was integrating UnitTest++ into my build environment. I use external makefiles to build static C++ libraries and the associated tests, and although the standard [...]]]></description>
			<content:encoded><![CDATA[<p>A recent post over on Acorn Heroes, <a href="http://acornheroes.com/?p=152">&#8220;Unit Testing and linking Static Libraries with XCode&#8221;</a>, has got me thinking: I went through a similar process a few months ago, when I was integrating <a href="http://gamesfromwithin.com/?p=51">UnitTest++</a> into my build environment. I use external makefiles to build static C++ libraries and the associated tests, and although the standard approach works well for the simulator, I still haven&#8217;t found a decent solution for the running on the iPhone itself (<a href="#iphone">read more below</a>).</p>
<h2><a name="simulator"></a>Unit testing on the iPhone Simulator</h2>
<p><strong></strong>Although this is a solved issue (using the &#8220;<a href="http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting">google-toolbox-for-mac</a>&#8221; approach), it still runs UI-less, which most of the time is fine. Approaches such as using <a href="http://www.mulle-kybernetik.com/software/OCMock/">OCMock</a> <a href="http://www.codingventures.com/2009/04/xcode-templates-for-iphone-static-libraries-with-unit-testing/">look</a> <a title="Nice article about iPhone testing with OCMock" href="http://iamthewalr.us/blog/2008/11/10/ocmock-and-the-iphone/">great</a>, but at the time I wanted to see if I could get unit testing running on the simulator <em>with the UI. </em></p>
<p>Using a combination of tools like <a href="http://www.fernlightning.com/doku.php?id=software:fseventer:start">fseventer</a> (which observes filesystem changes) and <a href="http://www.clarkwoodsoftware.com/peekaboo/">Peek-a-Boo</a> (which observes processes), I set about documenting the application startup process (on the simulator). From this, I cobbled together a script which I&#8217;d hope would do the trick&#8230; but unfortunately not <img src='http://rexy.co.uk/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . But I think it must be close!</p>
<p>I&#8217;ve put the salient points of the script at <a href="#script">the end of the post</a>, in case someone else has a solution.</p>
<h2><a name="iphone"></a>Unit testing on the iPhone</h2>
<p>Running tests from the command line (built via makefile) on the device is what I&#8217;d really like to find an answer to, but I haven&#8217;t really got very far with this <img src='http://rexy.co.uk/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>The strongest candidate at the moment may well be a combination of <a title="CMake - Cross Platform Make" href="http://www.cmake.org">CMake</a> to generate an XCode project file, and then using Applescript to launch the app, <a href="http://stackoverflow.com/questions/995424/xcode-test-automation-for-iphone">as others are discussing here</a>. Unfortunately the command-line tool xcodebuild doesn&#8217;t appear to have an option to launch applications.</p>
<p>Do you know of any alternatives?</p>
<p>For running test sub-projects (not built from the command line) the article <a href="http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html">Unit Testing Applications</a> on the Apple developer site is definitely worth reading, especially the section &#8220;Setting up Application Testing&#8221;, but again doesn&#8217;t help in my situation.</p>
<hr />
<h2><a name="script"></a>&#8220;Script&#8221; for running unit tests on the iPhone Simulator</h2>
<p>Finally, here are the snippets of the script I talked about earlier. I haven&#8217;t had time to revisit this since the release of OS 3.0, but if anyone else has tried anything similar I&#8217;d be very interested in hearing about it.  As I mentioned above, <strong>this script doesn&#8217;t work</strong>, so is only here for reference!</p>
<pre># Start the simulator, but wait...
"/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator" -SessionOnLaunch NO &amp;

# Get the pid of the simulator, we'll need that in a moment
pid=`ps wwax | egrep -i '[i]Phone Simulator' | awk '{ print $1 }'`</pre>
<p>Now I found I had to set the usual environment variables, as per the standard approach, namely, DYLD_ROOT_PATH, DYLD_FRAMEWORK_PATH, IPHONE_SIMULATOR_ROOT and CFFIXED_USER_HOME.</p>
<pre># Start the simulator bridge
"/Developer/Platforms/iPhoneSimulator./Developer/Applications/iPhone Simulator.app/Contents/MacOS/SimulatorBridge" $pid &amp;

# Had to unset some environment variables for the following commands to work.
unset DYLD_FRAMEWORK_PATH</pre>
<p>The following is where it gets a bit odd. I noticed a sequence of launchd, installd and securityd (which may need to be run as another user, possibly _securityd).</p>
<pre>#launchd - not sure what this is doing perhaps handling the following sequence.

# Run installd with a timeout of 30 seconds
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/libexec/installd -t 30 &amp;

# Run securityd - think this is something to do with entitlements
#/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/libexec/securityd

# Now start SpringBoard
"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/CoreServices/SpringBoard.app/SpringBoard" \
    -SBDisableAutoDim YES \
    -SBAutoLockTime -1 \
    -SBAutoDimTime -1 \
    -SBDontLockAfterCrash YES \
    -SBDidShowReorderText YES \
    -SBFakeBars YES \
    -SBDontAnimateAppleDown YES \
    -SBEnableDoubleHeightToggling YES &amp;

# Now start the app, which you'll find in some auto-generated folder in
"/Users/.../Library/Application Support/iPhone Simulator/User/Applications/.../test.app/test"</pre>
<p>There&#8217;s not a huge point in chasing a solution to this broken script, as the UI-less testing works so well. But, have you tried anything like this at all? It strikes me that the jail-breaking crowd may know more.</p>
]]></content:encoded>
			<wfw:commentRss>http://rexy.co.uk/2009/06/unit-testing-on-the-iphone-and-the-simulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
