MonkeyRunner
Author: Lijie Xia
What is Monkeyrunner


Providing an API for writing programs that control an android
device or emulator from outside of Android code.



Writing python based test tool and runing python script for
testing.



Sending keystrokes to device, takes screenshots of its user
interface, and stores screenshots on the workstation.



Testing applications and devices at the functional/framework
level and for unit test.
What can Monkeyrunner Do


Multiple device control



Functional testing



Regression testing



Extensible automation
Multiple Device Control


Apply one or more test suites across multiple devices or emulators


Physically attach all the devices or start up all the emulators (or
both) at once, connect to each one in turn programmatically, and
then run one or more tests.



Start up an emulator configuration programmatically, run one or
more tests, and then shut down the emulator

Functional testing Regression testing Extensible automation

Next Topic
Functional Testing


Monkeyrunner can run an automated start-to-finish test of an Android
application.



Programmers provide input values with keystrokes or touch events



Monkeyrunner takes screenshots to show the results.

Multiple device control Regression testing Extensible automation

Next Topic
Regression Testing


Test application stability by running an application and comparing its
output screenshots to a set of screenshots that are known to be
correct.

Functional testing Extensible automation Multiple device control

Next Topic
Extensible Automation


Develop an entire system of Python-based modules and programs for
controlling Android devices.



Developers can use the standard Python os and subprocess modules to
call Android tools such as Android Debug Bridge.

Multiple device control Functional testing Regression testing

Next Topic
Modules of Monkeyrunner(1)


MonkeyRunner: A class of utility methods for monkeyrunner
programs.





For connecting monkeyrunner to devices and emulators.
For creating UIs for Monkeyrunner programs.

MonkeyDevice: Represents a device or emulator.


For installing and uninstalling packages.



For starting an Activity.



For sending keyboard or touch events to an application.



Can also be used to run test packages.
Modules of Monkeyrunner(2)


MonkeyImage: Represents a screen capture image.


Capturing screens.



Converting bitmap images.



Comparing two MonkeyImage objects.



Writing images to files.
MonkeyRunner vs. Monkey Tool


Similarity:




Able to run on any emulator instance or on a device.

Difference:

MonkeyRunner

Monkey Tool

Write separate python script that can
install the program.

Generates events and sends them to
the system

Take screenshot for checking the
correctness

Test for crash or not.
Sustainability, performance, pricing


Monkeyrunner is a build in tool, which is included in the android SDK
tools.



Hence, it’s stabile for android testing and the performance is food.



Also, it’s free since it comes with Android SDK tools.
Benefit/Cost Analysis


Test program is implemented in Python.






Easy to learn.

Script is separate with the project files.

Able to test on multiple device and emulators at the same time.


Easy and powerful.
Compatibility


Multiple platform can handle MonkeyRunner.



Comes with Android SDK Tools.



Run on multiple devices and simulators.



Python is required.
Sample Code Tutorial
Tutorial / Basic Steps


Installs an application or test package



Runs an application



Send keystrokes or touch events to it



Take screen shots of the user interface



Store screen shots on your workstation
Reference


http://developer.android.com/tools/help/monkeyrunner_concepts.html



http://androidtesting.blogspot.com/2012/03/android-testing-withmonkeyrunner.html



http://androidtesting.blogspot.com/2012/04/monkeyrunner-tutorial-runningtests-on.html



http://antoine-merle.com/introduction-to-the-monkey-runner-tool-2/



http://developer.android.com/tools/help/monkey.html

Lijie xia lx223809 monkeyrunner