Monkey: A application Stress testing tools for Android mobile developers.

Shubham Patni
3 min readOct 1, 2018

--

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 explicit.

How this is useful !!. Usually in release cycle, we perform QA testing and before to do that we do Developer testing as well; but do we able to perform regression testing. Ohh yes, since I’m good in writing test case and that’s how I get assure. But my friend there is another one thing you need which is UI automation which should be full of stream of events.

Why we need UI automation testing !! This is very well explained here at developer forum

Testing user interactions within a single app helps to ensure that users do not encounter unexpected results or have a poor experience when interacting with your app. You should get into the habit of creating user interface (UI) tests if you need to verify that the UI of your app is functioning correctly.

Then why this monkey 🐵 tool !! Like any other app unit test cases you can write UI test case as you wish, but there will be still chance of missing stream of some events, and this is anyway need lot of time. And there this tool can help us. The best part it’s very very quick to setup, just single line of instruction and that mean no additionl code setup, no test case.

adb shell monkey -p <app_package> -v <event_count>

E.g. adb shell monkey -p appanal.mobi.com.navigationrnd -v 1000

It pickup very random events inside and outside of your application; and that’s how you can validate applicaiton navigation among the components.

Also note, it can be perform specific to application screen, just move to the screen and execute same command.

Since 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:

  1. open this feature in device “settings” > “security” > “screen pinning”
  2. click recent/multitasking button beside home button
  3. 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. In monkeyrunner you can have access of device and application component while monkey it’s complete automatic. Monkeyrunner used by QA to perform automation and can be useful in different way include UI comparison and all. Monkey simply give a very quick idea if any exception can be get by back and forth.

That’s it from the session. Happy Coding 🙌

--

--

Shubham Patni

#HumanBeing #Programmer #Android #AWS #ML #MedicalDeviceSoftware