Performance Testing using MONKEY tool for Android

16 / Jun / 2016 by Rahul Agarwal 0 comments

It’s surprising that only about 8% of developers actually test their application. There are so many buggy apps on the marketplace and it is quite disheartening for developers who take mobile app development seriously. “Release it now, fix it later” is a common practice these days. A buggy app will always cost the developer and the company their reputation.

A developer should not depend so much on testers for basic crashes and ANR(Application not responding) problems. As a developer myself, I can understand their tight deadline challenges. Keeping all these things in mind, Google has introduced Monkey tool, which takes care of crashes and ANR.

What is Monkey?
Monkey is a command line tool that runs over ADB shell command line. It generates N number of random events such as random touches, gesture, system level events, etc. and sends to the system or app which you want to test.

Why Monkey?
Monkey help developers perform Stress as well as Unit Tests at their end that takes as less as 5 sec. It helps catch frequent exceptions like NullPointerException, unhandled exception, ANR (Application not responding), etc. faster and easier. It also handles system level events like background application performance and parallelly running applications in a better manner.

How Monkey works?
It’s very simple, all you need to do is open the terminal or command prompt and navigate to the platform-tool directory:You may find it android >

android > SDK > platform-tool
Note: Install ADB in the directory platform-tool if not already there.

Now run your app in device or emulator through developing machine, navigate to the screen of your app which you want to test, and then run following command in the Terminal:

$ adb shell monkey -p your.package.name -v 500

Where:
-v : verbose method
500 : Number of random events which you want to generate at a time.

MONKEY tool will now generate 500 events for the given package. If all the events get executed successfully it will display that in the Terminal:

Events injected : 500
// Monkey finished

If all the events have not executed successfully, then it will print Error log in Android Studio and stop the events in the terminal with the same error.

A sample view is as follows

Terminal view

Terminal view

You can include the following events as per requirements:

-s <seed> : To execute same event each time, You have to use same seed value each time to generate same sequence of event.
--throttle <millisecond> : To slow down or insert delay in event execution.
--pct-touch<percent> : To Adjust percentage of touch event

Conclusion :
There are so many unit testing tools like Junit, Monkey, Espresso, etc. for different purposes. Out of all these tools, Monkey is the easiest to use with lots of features are as follows:

  • If your app crashes or has any sort of unhandled exception, it will stop and report the error
  • If there is any ANR, it will report
  • You can restrict it to any specific package

 

FOUND THIS USEFUL? SHARE IT

Leave a comment -