Androidmonkey Introduction to open source projects based on the instrumentation framework

Source: Internet
Author: User

In the previous article, "Monkeyrunner and Android device communication mode source analysis ," I mentioned that Monkeyrunner with the target Android machine is one way to interact with the target machine by opening the ' Monkey-port $port ' To interact with Monkeyrunner to establish a connection, and then intend to download the Android machine end of the monkey source code to analyze the monkey How to handle, in Google into the keyword "Android Monkey source code" and then navigate to the following connection " Https://code.google.com/p/androidmonkey ", see is Google and then again Android, think is the monkey that they want, so do not read more directly download for analysis.

The more confused the process, the biggest question is how monkey is to use instrumentation to inject the event? So how does it do to send events across process applications? Because according to my understanding instrumentation framework is not cross-process, and Monkey is absolutely cross-process!

@Overridepublic int fireEvent (instrumentation testruner) {String note;if (maction = = keyevent.action_up) {Note = "Action_ Up ";} else {note = "Action_down";} System.out.println (": Typing Key (" + Note + "):" + mkeycode+ "    //"); try {//testruner.sendkeysync (getEvent ()); TestRun Er.sendkeydownupsync (Mkeycode);} catch (Exception e) {System.out.println ("Failed to send key (" + Note + "):" + mkeycode+ "    //"); return monkeyevent.i Nject_fail;} return monkeyevent.inject_success;}
Tangled for a while back to the download place looked at the following overview, very short, but it is very clear that this is not what I want to monkey, but a native monkey made of a modified Android library. Since encountered in the way to translate its introduction and use it, anyway, so a few words, and then have time to further study it, as to whether it is really as I said can not cross the process, will be left to the future or everyone to verify.

1. Overview

Official text: Https://code.google.com/p/androidmonkey

Androidmonkey is an Android Library. It is, in fact, a copy of the original Android Monkey ToolHttp://developer.android.com/guide/developing/tools/monkey . html and made as a library for testing and analysis (e.g. code coverage) purposes.

Androidmonkey is an Android library. In fact, it is a test library based on native monkey that facilitates testing and analysis (e.g. code coverage).

Tester/user can easily use the library to create random test cases to test Android apps with GUI.

Testers/Users can easily use this library to create random test scripts for Android GUI applications

Why this library: Why use this library:

    • You can use the this library to the create random test cases for your application, with just few lines of code
    • With this library you can write random test cases for your app in just a few lines of code
    • You can add your assertions to access the state of the SUT (you can hardly does this with the Android Monkey Tool)
    • You can add assertions in your test code to make it easy to judge the current situation of your SUT (System/Application) (if you use monkey)
    • You can do coverages analysis of the random testing on Android application, this is useful for the Purpose (like what I ' m Doing
    • You can do this by testing your app for coverage analysis, which is useful for our research (as I do Now) (Translator Note: The last sentence should look like this: If you are a company purchasing, you want to assess whether an application is stable enough to meet your needs, Then you will try to do some preliminary research first.

Code Example/Code Instance
 Public class contactaddertest extends                ActivityInstrumentationTestCase2<Contactadder> {        Private intnum_events=  +;         Public contactaddertest() {                Super("Com.example.android.contactmanager", Contactadder.class);        }        @Override        protected voidsetUp() throws Exception {                Super.setUp();Setactivityinitialtouchmode(false);        }         Public voidtestmonkeyevents() {                DisplayDisplay=getactivity().Getwindowmanager().Getdefaultdisplay();                InstrumentationInst=getinstrumentation();                Packagemanagerpm=getactivity().Getpackagemanager();                MonkeyMonkey= New Monkey(Display,                                "Com.example.android.contactmanager",Inst,pm);                //Generate and fire a random event.                 for (intI= 0;I<num_events;I++) {Monkey.nextrandomevent();                }        }}

Official text: Https://code.google.com/p/androidmonkey/wiki/HowToUse


2. Introduction to use

howtouse /Introduction to use

Introduction/ Introduction

Here's how to use the library/ here's how to use this library:

Details/ detail

Create an Android Testproject/ build Android Projects

An Android Test project should is created first, using Android ADT [http://developer.android.com/sdk/eclipse-adt.html] refer the The Androidmonkey Library (jar or project)

Create an Android Test project item and add a reference to the Androidmonkey library via Android Adt[http://developer.android.com/sdk/eclipse-adt.html] ( Referencing a jar or project)

Create a test class

Create a normal ACTIVITYINSTRUMENTATIONTESTCASE2 test class, and add the following test case:

Create a generic ActivityInstrumentationTestCase2 test class, and then add the following test case code:

public void Testmonkeyevents () {Display display = Getactivity (). Getwindowmanager (). Getdefaultdisplay (); Instrumentation inst = getinstrumentation (); Packagemanager pm = getactivity (). Getpackagemanager (); Monkey Monkey = new Monkey (display, packagetotest, Inst, PM); for (int i = 0; i < num_events; i++) {Monkey.nextrandomeven T ();}}



Androidmonkey Introduction to open source projects based on the instrumentation framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.