Performance Testing using MONKEY tool for Android
Monkey is as tool that perform regression testing on application using some very random events. It’s come up with Android SDK installation so no need to install separately .
What is Monkey?
It is a simple 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?
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
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 1000
Where:
-v : verbose method
1000 : Number of random events which you want to generate at a time.
MONKEY tool will now generate 1000 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.
Since this tool generate very random event and so it play with system UI as well like toggle Wifi/BT state and so on. But in case if you only wants to test inside the application only, for device user 5.0+(Lollipop) you have Screen Pinning feature.
Using screen pinning you can pin(lock) the application. To enble this here is the manual instruction:
open this feature in device “settings” > “security” > “screen pinning”
click recent/multitasking button beside home button
click the green pin icon to pin the Application you want to test
And you done, using the same instruction will generate event inside the application.
To remove it you just need to hold back and overview tab for a while and system will release pinning way.
For developers this can be issue with Emulator as you can not hold both the option in single shot. So you have powerful adb access now.
adb shell am task lock stop
This may throw message like “Activity manager is not in lockTaskMode” but no worry you are done. Screen is unpinned now . Alternatively you can restart emulator.
Note: monkey and monkeyrunner are two different tools.