@mSolo
        
        2015-04-16T05:48:26.000000Z
        字数 3780
        阅读 1841
    Android 测试 TDD 持续集成
$ emulator -avd testdevice -no-window -no-audio -no-boot-anim -port 5580
$ adb -s emulator-5580 install YourApp.apk$ adb -s emulator-5580 shell am instrument -w\com.blundell.tut.test/android.test.InstrumentationTestRunnercom.blundell.tut.test.MyTests:......com.blundell.tut.test.MyOtherTests:..........Test results for InstrumentationTestRunner=..................Time: 15.295OK (20 tests)
$ adb -s emulator-5580 emu event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0 
@Overridepublic void setUp() throws Exception {Activity activity = getActivity();Window window = activity.getWindow();window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);}
清理,重启模拟器 
$ adb -s emulator-5580 shell 'stop; sleep 5; start' 
$ emulator -avd testdevice -no-window -no-audio -no-boot-anim -port 5580 -wipe-data
终止模拟器 
$ adb -s emulator-5580 emu kill
其它例子
$ emulator -avd testdevice -no-window -no-audio -no-boot-anim -port 5580 -proppersist.sys.language=ja -prop persist.sys.country=JP
For network speed:
| Option | Description | Speeds [kbits/s] | 
|---|---|---|
| -netspeed gsm | GSM/CSD | Up: 14.4, down: 14.4 | 
| -netspeed hscsd | HSCSD | Up: 14.4, down: 43.2 | 
| -netspeed | gprs GPRS | Up: 40.0, down: 80.0 | 
| -netspeed edge | EDGE/EGPRS | Up: 118.4, down: 236.8 | 
| -netspeed umts | UMTS/3G | Up: 128.0, down: 1920.0 | 
| -netspeed hsdpa | HSDPA | Up: 348.0, down: 14400.0 | 
| -netspeed full | No limit | Up: 0.0, down: 0.0 | 
| -netspeed | Select both the upload and download speed | Up: as specified, down: as specified | 
| -netspeed : | Select the individual up and down speed | Up: as specified, down: as specified | 
For latency:
| Option | Description | Delay [msec] | 
|---|---|---|
| -netdelay gprs | GPRS | Min 150, max 550 | 
| -netdelay edge | EDGE/EGPRS | Min 80, max 400 | 
| -netdelay umts | UMTS/3G | Min 35, max 200 | 
| -netdelay none | No latency | Min 0, max 0 | 
| -netdelay | Select exact latency | Latency as specified | 
| -netdelay : | Select min and max latencies | Minimum and maximum latencies as specified | 
$ emulator -avd testdevice -port 5580 -netspeed gsm -netdelay gprs
$ telnet localhost 5580network statusCurrent network status:download speed: 14400 bits/s (1.8 KB/s)upload speed: 14400 bits/s (1.8 KB/s)minimum latency: 150 msmaximum latency: 550 msOK
kextstat | grep intel 
$ adb -e shell monkey -p com.blundell.tut -v -v 1000Events injected: 1000:Sending rotation degree=0, persist=false:Dropped: keys=0 pointers=4 trackballs=0 flips=0 rotations=0## Network stats: elapsed time=2577ms (0ms mobile, 0ms wifi, 2577ms not connected)// Monkey finished
$ adb -e shell monkey -p com.blundell.tut --port 1080 &$ adb -e forward tcp:1080 tcp:1080$ telnet localhost 1080tap 150 200
# monkeytap 200 200 # Touch and select the edit text inputtype HelloWorld # Type Hello Worldtap 200 350 # Tap the button to show the toasttap 200 200 # Touch and select the edit text againpress DEL # delete the textpress DELpress DELpress DELpress DELtype Monkey # Type Monkeytap 200 350 # Tap the button to show the toast Hello Monkey
$ adb shell am start -n com.blundell.tut/.MonkeyActivity$ nc localhost 1080 < ch_4_code_ex_10.txt
#! /usr/bin/env monkeyrunnerimport sys# Imports the monkeyrunner modules used by this program from com.android.monkeyrunner# import MonkeyRunner, MonkeyDevice, MonkeyImage# Connects to the current device, returning a MonkeyDevice objectdevice = MonkeyRunner.waitForConnection()if not device:print >> sys.stderr, "Couldn't" "get connection"sys.exit(1)device.startActivity(component='com'.blundell.tut/.MonkeyActivity')MonkeyRunner.sleep(3.0)device.type("hello")# Takes a screenshotMonkeyRunner.sleep(3.0)result = device.takeSnapshot()# Writes the screenshot to a fileresult.writeToFile('/tmp/device.png')device.press('KEYCODE_BACK', 'DOWN'_AND_UP')

$ monkey_playback.py script.mr