Android Programming Tutorials

(Romina) #1
Take a Monkey to Lunch

Note that if you did not add your SDK's tools/ directory to your system


PATH, you may need to change to that directory to get this command to


execute properly.


This command indicates:



  • You want to run the Monkey

  • You want the Monkey to limit itself to testing your application (-p
    apt.tutorial), so if the Monkey attempts to do something that


would exit your application (e.g., click the HOME button), that
simulated input will be skipped


  • You want the Monkey to execute one event every 100 milliseconds
    (--throttle 100)

  • You want the Monkey to be verbose and report what events it
    simulates (-v)

  • You want the Monkey to perform 600 simulated events


What you should see is the LunchList application running amok, as if some


monkey were trying out different UI operations (clicking buttons, typing in


fields, choosing menu options). If all goes well, LunchList will survive


without errors. If something goes wrong, you will get an exception, and can


use the log information (via DDMS or adb logcat) to see what failed and,


possibly, how to fix it.


Your shell will show a running tally of what has been done, such as


simulating screen taps or key presses.


Extra Credit...............................................................................................


Here are some things you can try beyond those step-by-step instructions:



  • Try updating your test process to be repeatable, so if you encounter
    some sort of exception, you can make it happen again. To do this,


you will need to save your database file (stored in
/data/data/apt.tutorial/databases/lunchlist.db) before running

Monkey with the -s switch to provide a known seed value. Each test


336
Free download pdf