In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Instrumentation Framework-based open source project AndroidMonkey is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
One of the biggest questions is how monkey uses instrumentation to inject event. In that case, how can it send events across process applications? Because according to my understanding of the instrumentation framework can not cross-process, and monkey is absolutely cross-process!
@ Override public 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 ()); testRuner.sendKeyDownUpSync (mKeyCode) } catch (Exception e) {System.out.println ("Failed to send key (" + note + "):" + mKeyCode + "/ /"); return MonkeyEvent.INJECT_FAIL;} return MonkeyEvent.INJECT_SUCCESS;}
After struggling for a period of time, I went back to the download place to take a look at the overview, which is very short, but clearly describes that this is not the monkey I want, but a modified android library of native monkey. Since we have encountered it, let's translate its introduction and use. Anyway, there are only a few words, and we will further study it in the future. As to whether it really cannot cross the process as I said, it will be left to the future or everyone to verify it.
1. Overview
AndroidMonkey is an android library. In fact, it is a test library based on native monkey to facilitate testing and analysis (for example, code coverage).
Testers / users can easily use this library to create random test scripts for Android gui applications
Why this library:
Why use this library:
With this library, you can write random test cases for your app in just a few lines of code.
You can add assertions to your test code to easily determine the current situation of your SUT (system / application under test) (it is difficult to do so if you use monkey).
You can do a coverage analysis of your app through a random test, which is very useful for our research (like what I'm doing now). (translator's note: in fact, this last sentence should be understood like this: if you are a company buyer, and you want to evaluate whether an application is stable enough to meet your needs, then you will try it and do some preliminary research first.)
Code example/ code example public class ContactAdderTest extends ActivityInstrumentationTestCase2 {private int NUM_EVENTS = 1000; public ContactAdderTest () {super ("com.example.android.contactmanager", ContactAdder.class);} @ Override protected void setUp () throws Exception {super.setUp (); setActivityInitialTouchMode (false) } public void testMonkeyEvents () {Display display = getActivity (). GetWindowManager (). GetDefaultDisplay (); Instrumentation inst = getInstrumentation (); PackageManager pm = getActivity (). GetPackageManager (); Monkey monkey = new Monkey (display, "com.example.android.contactmanager", inst, pm) / / Generate and fire a random event. For (int I = 0; I < NUM_EVENTS; iTunes +) {monkey.nextRandomEvent ();}
two。 Introduction to use
Introduction to use
Brief introduction
Here is how to use this library:
Details
C create an android project
First create an Android Test Project project and add a reference to the AndroidMonkey library (reference jar or project) through Android ADT [http://developer.android.com/sdk/eclipse-adt.html]]
Create a test class
Create a normal 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; iTunes +) {monkey.nextRandomEvent ();}} will it help you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.