Debugging Tutorial – Automating Your Tests With A UIRecorder Instrument

  • Twitter
  • Facebook
  • Digg
  • Reddit
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
October 6th, 2009 Posted by: (ELC) - posted under:Tutorials

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.

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!

  • Mustafa

    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! :)

  • Mustafa

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

  • Arne

    Brandon, thanks for the great tip :)

  • http://brandontreb.com Brandon

    @Mustafa

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

  • http://www.cpriphoneapp.com Matt

    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.

  • http://www.hueslerinformatik.ch/blog Patrick Huesler

    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/

  • http://twitter.com/MyHumbleSelf Catalin

    How about a debugger-tutorial?

  • Mustafa

    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.

  • http://sivasankarmobiledevelopment.wordpress.com/2010/05/28/debugging-tutorial-%e2%80%93-automating-your-tests-with-a-uirecorder-instrument/ Debugging Tutorial – Automating Your Tests With A UIRecorder Instrument « Sivasankar's Blog

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

  • http://sivasankarmobiledevelopment.wordpress.com/2010/05/28/debugging-tutorial-%e2%80%93-automating-your-tests-with-a-uirecorder-instrument/ Debugging Tutorial – Automating Your Tests With A UIRecorder Instrument « Sivasankar's Blog

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

  • Nagarajan R

    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

  • http://vodkhang.wordpress.com/2010/06/28/iphone-development-tools/ IPhone development tools « Software Development, Research and Learn

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

  • http://sdrftjhwh65.com Angel Digirolomo

    Insightful blog=) I am going to want some time to think about this writing.

  • http://blackdiamondengagementringss.com/ Black Diamond Engagement Rings

    What exactly anyone said created plenty of perception. Nevertheless, think about this, what if anyone additional somewhat subject matter? Get real, POST dont want to say how you can run your current web log, yet what if you included one thing to be able to probably acquire peoples interest? As being a video tutorial as well as any image or even two to get persons excited about what exactly youve got a chance to point out. For me, may well make ones web site turn on a small amount.

blog comments powered by Disqus