The previous article was written on Android's own automated test (1) How to install and uninstall the application (Java), and then explore the assumptions in a normal Java application, based on the ID to find the object
1, the class library depends on:
The Library dependencies is:
Chimpchat.jar,common.jar,ddmlib.jar,guava-13.0.1.jar,sdklib.jar,hierchyviewer2lib.jar
They can all is found in the Sdk/tools/lib subdirectory of the ADT bundle.
2. Code:
Package Com.robot.dream.test;import Com.android.chimpchat.adb.adbbackend;import Com.android.chimpchat.adb.linearinterpolator.point;import Com.android.chimpchat.core.ichimpdevice;import Com.android.chimpchat.core.touchpresstype;import Com.android.chimpchat.hierarchyviewer.hierarchyviewer;import Com.android.hierarchyviewerlib.models.viewnode;public class Testrobotdream {public static point Getabsolutecenterofview (Viewnode node) {Point point = Getabsolutepositionofview (node); return new Point (Point.getx () + NODE.WIDTH/2, point.gety () + NODE.HEIGHT/2); public static point Getabsolutepositionofview (Viewnode node) {int x = Node.left; int y = node.top; for (Viewnode p = node.parent; P! = null; p = p.parent) {x + = P.LEFT-P.SCROLLX; Y + = p.top-p.scrolly; } return new Point (x, y); }/** * @param args */public static void main (string[] args) {System.out.println ("start"); IChimpdevice device = new Adbbackend (). Waitforconnection (); SYSTEM.OUT.PRINTLN ("Device OK"); Device.shell ("AM Start com.robot.dream/com.robot.dream.mainactivity"); System.out.println ("Monkey Test Connected"); Hierarchyviewer view = Device.gethierarchyviewer (); Viewnode Viewnode = View.findviewbyid ("Id/center_image"); Point P = Hierarchyviewer.getabsolutecenterofview (Viewnode); Point P = Getabsolutecenterofview (Viewnode); Easymonkeydevice easydevice = new Easymonkeydevice (null); System.out.println ("x:" +p.getx () + "Y:" +p.gety ()); By.id (""); by selector = By.id (""); System.out.println ("Touch 1 OK"); Device.touch (P.getx (), P.gety (), touchpresstype.down_and_up); System.out.println ("Touch 2 OK"); Device.touch (P.getx (), P.gety (), touchpresstype.down_and_up); Easydevice.touch (selector, touchpresstype.down_and_up); Device.dispose (); }}
3. Limitations:
The above self-motivated test, such a way is to use Monkeyrunner corresponding Java, lib to achieve.
So it's essentially Java version of Monkey Runner
The functionality it can achieve. Basically monkey Runner can also be implemented, assuming Java implementation. Fewer documents. Less material. It's worth the candle.
Explore Java to achieve, the biggest harvest is to these test-related classes of learning.
4, the following will introduce some Android monkeyrunner &android Unit Auto test&android Code Coverage Test
Android own automated Tests (2) Find objects by ID (Java)