This is part of an ELC Tech Network

Debugging Tutorial – Automating Your Tests With A UIRecorder Instrument

If you have ever experienced a bug in your application that took many steps to reproduce, then this tutorial is for you.  By nature, testing and debugging are very tedious processes.  This is especially the case for the iPhone.

Say you have an app that drills down 5-levels deep to some other view.  Now let’s say that you have a bug on that view 5 levels deep.  Your normal method of debugging is:

  • Run the app
  • Tap view 1
  • Tap view 2
  • Tap view 3
  • Tap view 4
  • Tap view 5
  • (Crash)
  • Change some code
  • Repeat

As you can see (and I’m sure have noticed), this sucks.  Well, Kendall Gelner gave a killer talk at 360iDev (which I recently attended) on various debugging tips using Instruments and XCode.  One of the most useful techniques (to me) was how to automate your testing.  Let me show you what I mean.

1. Open up the app you wish to test/debug

2. Launch it in the simulator

3. Open Instruments – This is located in /Developer/Applications/Instruments (just do a spotlight search for it)

screenshot_01

4. Select UIRecorder and click Choose - You should now see a window like this

screenshot_02

5. Now, we need to attach this tool to the iPhone Simulator process.  Click the drop-down above Default Target -> Attach to Process -> iPhone Simulator.

Advertisement

ss_03

6. Now click Drive & Record and do all of the steps in the simulator to test your app.  At this point, the UI Recorder is recording your every move.  When you have finished press the Stop button. Note: After you have recorded your actions, don’t move the simulator as it will mess up the entire process.

7. Modify your code…

8. Press the Drive & Record button and watch the magic happen.  The test is automatically done for you.  You should see your mouse move over to the simulator and the system mimicking every action that you did before.

That’s it! I know this isn’t a super long tutorial (or even a coding tutorial), but the UI Recorder has sped my test time up tremendously.  Give it a shot and let me know what you think.  Here is a short video of me going through all of the steps.

iCodeBlog – Debugging Tutorial – Automating Your Tests With A UIRecorder Instrument from Brandon Trebitowski on Vimeo.

Happy iCoding!

This entry was posted in iPhone Programming Tutorials, iphone and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

9 Comments

  1. Mustafa
    Posted October 6, 2009 at 9:29 pm | Permalink

    I have a few small requests.

    1. Please make these videos available for download.
    2. I would love to see a detail tutorial on other Instruments tools as well.

    Keep ‘em coming! :)

  2. Mustafa
    Posted October 6, 2009 at 9:57 pm | Permalink

    * 1. Please make these videos available for download.
    I’m specially interested in MapKit screencast video.

  3. Arne
    Posted October 7, 2009 at 1:23 am | Permalink

    Brandon, thanks for the great tip :)

  4. Posted October 7, 2009 at 9:00 am | Permalink

    @Mustafa

    I believe you can click on the Vimeo link and download the .mov from there.

  5. Posted October 7, 2009 at 1:25 pm | Permalink

    Brandon, another great tutorial! This is really powerful. I’m thinking that an extension to this would be to use an apple script to drive the UIRecorder and then have the apple script verify the app’s NSLog output. For example, you could have the apple script tell UIRecorder to hit a button, then the script could check that a certain sequence of events happened as a result.

  6. Posted October 8, 2009 at 6:01 am | Permalink

    Interesting approach. The drawback with this approach is that you can’t make any assertions programatically. You have to look at it and decide whether the behaviour is corret or not.

    There is a project called uispec which allows you to drive the ui with code and make assertions on it. I have written an article about it: http://www.huesler-informatik.ch/2009/08/18/iphone-testing-the-lay-of-the-land/

  7. Posted October 8, 2009 at 2:07 pm | Permalink

    How about a debugger-tutorial?

  8. Mustafa
    Posted October 10, 2009 at 1:39 am | Permalink

    Ah… i read somwhere that vimeo shows Download link (if the uploader allow), but i didn’t knew that you have to be a registered member to download the movie. Plus, the link to download the video is on the bottom right corner (I didn’t catch that the first time).

    Thanks.

  9. Nagarajan R
    Posted June 18, 2010 at 1:04 am | Permalink

    Hi,
    How to play the recorded actions using UIRecorder in Instruments…I saved the file, it stored as .trace extention…want to know how to run this .trace file at a later point of time.
    Thanks
    Nagaraj

2 Trackbacks

  1. [...] Programming Tutorials, iphone and tagged iPhone Coding, iphone debugging, uirecorder. Bookmark the permalink. Post a comment or leave a trackback: Trackback [...]

  2. [...] 4/ UI Automation Test: XCode Instrument [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">