How Monkey Testing command can be useful in Automation


We usually see every QA engineer executing many test cases for regression testing manually during the sprint cycle. And during this time we tend to forget (or sometimes neglect) to perform some stress testing on  applications. Even if the tester tries different scenarios by putting random values and checking, there are very less chances of identifying application crashes or ANR. In every release cycle, it is very important to check the stability, reliability and efficiency of Mobile Apps before pushing it to production. This is where monkey testing can make things easy for testers.

Overview

Monkey testing is a technique used by QA engineers or developers to test  applications randomely and observe if the device or application crashes or gives any ANR (Application Not Responding) alert/message. This type of testing comes into picture when there is insufficient time to do stress testing. 

This testing helps us to evaluate whether the application crashes when unexpected input values are provided. Here the inputs could be data that is entered into the application or tapping a button for the next page or clicking on a link to navigate to the next page.

Advantages of Monkey Testing

  1. This type of testing is more effective and efficient while doing stress testing.
  2. New bugs such as ANR’s or crashes in apps can be discovered through monkey tests which ideally would not have been found during regression testing.
  3. There are no steps or specifications for performing this test.
  4. Monkey testing completely focuses on crashing the device or application by entering random inputs, so the testers can guarantee the robustness of the application.
  5. We can create an automation suite or .bat file by adding the Monkey Testing Command which can trigger inputs continuously and get results without manual effort.
  6. This type of testing can be performed for desktop apps, web apps, and also mobile applications.

Usage of Monkey Testing via Automation

At times, customers come with the problem that the application is crashing suddenly or shows ANR after using it for quite a long period of time. But testers may not succeed in reproducing such issues by just doing normal regression testing. During sprint cycles, testers tend to be more inclined towards testing the feature or the module that is being assigned to them, and due to time constraints, forget testing some random scenarios.

So with the help of monkey test automation, testers can relax and just trigger the suite continuously for a longer period of time and identify all possible crashes and ANRs well in advance and get them fixed before pushing the app to production.

Below is the simple ADB (Android Debug Bridge) command that can be used to integrate in our selenium code.

ADB command

adb shell monkey -p <your.package.name> -v <seed>

The following example shows how we can write a simple Selenium script and run it via a batch file.

After this we can create a .bat extension file. So, instead of opening the eclipse tool and running it everytime, we can simply run the batch file which will automatically trigger the suite and give us the results.

Below screenshot shown is the sample batch file

In the above batch file, we can add the adb command with the desired application package name and add the seed the value for those many click events required.

Conclusion

We use monkey testing to identify the scenarios in which the customer might use the application in real life. Not every customer uses the application in the way it’s meant to be used. There are customers who bombard the application with random inputs when they don’t get the expected results. Thus the testers need to verify the application from a customers’ perspective. To a certain extent, monkey t(not 100%) helps us to prevent such scenarios where the application might break due to unexpected inputs.

Leave A Comment

Your email address will not be published. Required fields are marked *