Archive

Posts Tagged ‘testing’

iPhone Dev Note #22: UIAutomation

October 5th, 2010 rupert No comments

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

simulator.png

2. I can’t get the mainWindow().buttons(). Why?

Related code shown below have a navigation view added as a subview to window. Don’t confuse yourself that you need to get a subview from mainWindow() like mainWindow().elements[0]? It will not work. There’s nothing wrong with your code, however, open up your xib or Interface Builder, in my case, I will open MenuController.xib.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	[self createEditableCopyOfDatabaseIfNeeded];
 
	MenuController *mainMenuController = [[MenuController alloc] initWithNibName:@"MenuController" bundle:nil];
	navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenuController];
 
	[window addSubview: [navigationController view]];
	[mainMenuController release];
 
    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

test-1.gif

For some reason, when the “Accessibility” is enabled on the view, it doesn’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.

test-2.gif

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.

3. How was I able to see the element heirarchy?

...mainWindow().logElementTree();

As always don’t keep banging your head that there’s something wrong with your view heirarchy. I suggest you read thoroughly the reference posted above to understand what is available for mainWindow().

4. Instrument tips
- Command + R will stop or record the test.
- Your app is not listed in the “Choose target”? 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.

Categories: iphone Tags: , ,

Rails Note #11: TDD and Loading Development Fixtures for Testing

November 25th, 2008 rupert No comments

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, 'WHOISD-ABONENT'=> MOBILE_NUMBER, :categ_id => '123', :node_id => '10', :page => '2'

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.

assert_equal assigns("sub_menus").length, 2

4. Code the controller

5. Code the view

6. Test from the browser.

7. Refactor the testcase and make more assertions.

8. Run the testcase

Now, it could be very hard to execute the tests if you don’t have the same development data inside your testing database. I found a good tip from the Rail’s Way book, and used ar_fixtures.

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:

$ script/plugin install http://topfunky.net/svn/plugins/ar_fixtures

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:

$ rake db:fixtures:dump MODEL=BillingCode
Categories: rails Tags: , ,