<?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>mobile and gis dev notes &#187; testing</title>
	<atom:link href="http:///wordpress/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:26:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iPhone Dev Note #22: UIAutomation</title>
		<link>/wordpress/2010/10/iphone-dev-note-22-uiautomation/</link>
		<comments>/wordpress/2010/10/iphone-dev-note-22-uiautomation/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 03:34:19 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/wordpress/?p=774</guid>
		<description><![CDATA[One of the problems with UIAutomation is the lack of documentation. At the time of writing this, the current documentation/reference that I use is found here ( http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html ) 1. Works on the device but not on the simulator? Copy com.apple.Accessibility.plist from 4.0 to 4.0.1 2. I can&#8217;t get the mainWindow().buttons(). Why? Related code shown [...]]]></description>
			<content:encoded><![CDATA[<p>One of the problems with UIAutomation is the lack of documentation. At the time of writing this, the current documentation/reference that I use is found here ( <a href="http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html">http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html</a> )</p>
<p>1. Works on the device but not on the simulator?</p>
<p>Copy com.apple.Accessibility.plist from 4.0 to 4.0.1</p>
<p><img src="/wordpress/wp-content/uploads/2010/10/simulator.png" alt="simulator.png" border="0" width="459" height="431" /></p>
<p>2. I can&#8217;t get the mainWindow().buttons(). Why?</p>
<p>Related code shown below have a navigation view added as a subview to window. Don&#8217;t confuse yourself that you need to get a subview from mainWindow() like mainWindow().elements[0]? It will not work. There&#8217;s nothing wrong with your code, however, open up your xib or Interface Builder, in my case, I will open MenuController.xib.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self createEditableCopyOfDatabaseIfNeeded<span style="color: #002200;">&#93;</span>;
&nbsp;
	MenuController <span style="color: #002200;">*</span>mainMenuController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MenuController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MenuController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	navigationController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationController alloc<span style="color: #002200;">&#93;</span> initWithRootViewController<span style="color: #002200;">:</span>mainMenuController<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>navigationController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>mainMenuController release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch</span>
    <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2010/10/test-1.gif" alt="test-1.gif" border="0" width="558" height="641" /></p>
<p>For some reason, when the &#8220;Accessibility&#8221; is enabled on the view, it doesn&#8217;t work. I am not exactly sure why, but UIAutomation only recognizes the window and not its sub-elements. Unticking this checkbox, allows us to get all the elements under mainWindow(). This has been a bugger and I spent 4 hours figuring this.</p>
<p><img src="/wordpress/wp-content/uploads/2010/10/test-2.gif" alt="test-2.gif" border="0" width="558" height="637" /></p>
<p>After you finished updating your elements in Interface Builder, make sure you build and deploy the app in the simulator. This will recreate/replace the binary and remember that it is the target app of Instruments. Afterwards, launch the test script and see if it works now. </p>
<p>3. How was I able to see the element heirarchy?</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">...mainWindow<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>.logElementTree<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>As always don&#8217;t keep banging your head that there&#8217;s something wrong with your view heirarchy. I suggest you read thoroughly the reference posted above to understand what is available for mainWindow().</p>
<p>4. Instrument tips<br />
- Command + R will stop or record the test.<br />
- Your app is not listed in the &#8220;Choose target&#8221;? Well you could navigate to the /Users/rupert/Library/Application Support/iPhone Simulator/4.0.1/Applications/94EC26E5-D76B-4003-9675-8F0DDE111D01/beforeUdig.app/ (which sucks) OR from XCode > Run > Run With Perfomance Tool > Leaks. Once Leaks opens, it automatically chooses your current app as the target. Close leaks and go back to Instruments. From here, you will see your app listed in the target.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/10/iphone-dev-note-22-uiautomation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #11: TDD and Loading Development Fixtures for Testing</title>
		<link>/wordpress/2008/11/ruby-on-rails-tdd-and-loading-development-fixtures-for-testing/</link>
		<comments>/wordpress/2008/11/ruby-on-rails-tdd-and-loading-development-fixtures-for-testing/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 11:32:10 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/wordpress/?p=301</guid>
		<description><![CDATA[Here is a brief outline on how I am doing test driven development personally. 1. Code up tests/functional/foo_controller_test.rb until you know what you expect from the method. Make the test method as self explanatory as much as possible. def test_goto_restaurant_next end 2. Imagine how the URL parameters will be passed to the controller. get :goto, [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a brief outline on how I am doing test driven development <em>personally</em>.</p>
<p>1. Code up tests/functional/foo_controller_test.rb until you know what you expect from the method. Make the test method as self explanatory as much as possible.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> test_goto_restaurant_next
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>2. Imagine how the URL parameters will be passed to the controller.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">get <span style="color:#ff3333; font-weight:bold;">:goto</span>, <span style="color:#996600;">'WHOISD-ABONENT'</span><span style="color:#006600; font-weight:bold;">=&gt;</span> MOBILE_NUMBER, <span style="color:#ff3333; font-weight:bold;">:categ_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'123'</span>, <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'10'</span>, <span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'2'</span></pre></div></div>

<p>3. At this point. It gets too exciting to code up the controller itself. Hold on, try to make an assertion on a variable that we will use in the view.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">assert_equal assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;sub_menus&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">length</span>, <span style="color:#006666;">2</span></pre></div></div>

<p>4. Code the controller</p>
<p>5. Code the view</p>
<p>6. Test from the browser.</p>
<p>7. Refactor the testcase and make more assertions.</p>
<p>8. Run the testcase</p>
<p>Now, it could be very hard to execute the tests if you don&#8217;t have the same <strong>development data</strong> inside your <em>testing</em> database. I found a good tip from the Rail&#8217;s Way book, and used ar_fixtures.</p>
<p><cite>For whatever reason, dumping data to fixtures is not a part of core Rails. Considering that Rails gives you a to_yaml method on ActiveRecord models and Hash objects, it wouldn’t be too hard to write your own Rake task. However, it’s not necessary to do so because of a well-proven plugin written by Geoff Grosenbach. It’s called ar_fixtures and you can install it with the following command:<br />
</cite></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ script<span style="color:#006600; font-weight:bold;">/</span>plugin install http:<span style="color:#006600; font-weight:bold;">//</span>topfunky.<span style="color:#9900CC;">net</span><span style="color:#006600; font-weight:bold;">/</span>svn<span style="color:#006600; font-weight:bold;">/</span>plugins<span style="color:#006600; font-weight:bold;">/</span>ar_fixtures</pre></div></div>

<p><cite>Once the plugin is installed, dumping a fixture is a simple matter of invoking a new rake task called rake db:fixtures:dump. Unlike the built-in loading rake task, this one takes a MODEL parameter with the name of the ActiveRecord class that you want to dump data for:</cite></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ rake db:fixtures:dump MODEL=BillingCode</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/ruby-on-rails-tdd-and-loading-development-fixtures-for-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

