{"id":79,"date":"2013-06-28T01:36:59","date_gmt":"2013-06-28T01:36:59","guid":{"rendered":"https:\/\/code4reference.com\/?p=79"},"modified":"2023-10-01T13:34:32","modified_gmt":"2023-10-01T13:34:32","slug":"code4referencemonkey-test-on-android-application","status":"publish","type":"post","link":"https:\/\/code4reference.com\/?p=79","title":{"rendered":"Monkey test on Android application"},"content":{"rendered":"<p>You may be wondering about the test name or thinking that it may be a misnomer. Well, this is not a misnomer. It is a kind of stress test done on an application.<\/p>\n<h4>Monkey Test:<\/h4>\n<p>Monkey test is a kind of Unit test that runs with no specific test case in mind. Test cases are randomly selected and executed. For example, giving random string to text-field or clicking some random buttons of the application. These kind of test cases check the stability of the application. Monkey test is a kind of black box test.<br \/>\nIn my career, I have seen such kind of tests in telecommunication domain (handset\u00a0manufacturer). In such test cases, the tester can do any sort of random things on the phone and check whether the phone application can handle such scenario or not.\u00a0In real world no one is going to educate people about how to use the phone. They\u00a0use the phone in N number of ways and expect it to work under all circumstances.\u00a0<\/p>\n<h4>Android Monkey test:<\/h4>\n<p>If you are an Android application developer and want to do Monkey test on the application, then you can use Android Monkey command line application. It\u00a0generates a stream of random pseudo user events such as button click, touch, gesture etc.\u00a0This application can be run on your device or emulator. Monkey test can be used to do stress test on the application.<\/p>\n<p><strong>Perquisite<\/strong><strong>:<\/strong>\u00a0Android SDK should be present and\u00a0Android Debug Bridget(ADB) should be\u00a0accessible.\u00a0<\/p>\n<p>During the test if an exception occurs or the application crashes, then Monkey will stop the execution or you can even instruct Monkey to continue the test after exception. It also provides certain debugging configurations where you can configure monkey to get the test execution log.<br \/>\nYou may be wondering if Monkey randomly generates the events, \u00a0then is it possible to create the same test scenario? I would say yes, Monkey takes care of that. If you give the same seed value (-s option) then Monkey creates same sequence of events. This feature enables you to reproduce the same scenario and allows to take the log and analayze the issue.<\/p>\n<h4>Running Monkey test on Android application:<\/h4>\n<pre>\n\n#basic command format:\n$ adb shell monkey [options] \n#To get command argument information, run the following command.\n$ adb shell monkey --help\n#The command below exercises monkey test on given package(your.package.name here)\n# It enables the verbosity and fires 500 random events\n$ adb shell monkey -p your.package.name -v 500\n#If you want to increase the verbosity, then increase the number of v like shown below.\n#The default verbosity is Level 0 which shows minimum information,\n#i.e startup notification, test completion, and final results\n$ adb shell monkey -p your.package.name -vvv 500\n#you can also target activity with certain category\n#e.g android.intent.category.LAUNCHER\n$ adb shell moneky -p your.package.name -c android.intent.category.LAUNCHER -v 500\n#The throttle option enables you to keep delay between events.\n#The command below fires events after 3 seconds and generates 50 events.\n$adb shell monkey -p your.package.name -v -throttle 3000 50\n<\/pre>\n<p>you can know more about\u00a0<a href=\"http:\/\/developer.android.com\/tools\/help\/monkey.html\">Application Exerciser Monkey here<\/a><\/p>\n<p>Monkey, sometimes, creates problem with adb server. If you notice that adb server is not behaving properly, then you may have to restart the server. Use the following command to do so.<\/p>\n<pre>\nadb kill-server\nadb start-server <\/pre>\n<p>Your valuable comments are always welcomed. It will help to improve my post and understanding.<\/p>\n<p><em>\u201cBy three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest.\u201d\u00a0<\/em><br \/>\nBy : Confucius<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may be wondering about the test name or thinking that it may be a misnomer. Well, this is not a misnomer. It is a kind of stress test done on an application. Monkey Test: Monkey test is a kind of Unit test that runs with no specific test case in mind. Test cases are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":1,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions\/352"}],"wp:attachment":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}