@mSolo
2015-04-16T13:48:26.000000Z
字数 3780
阅读 1756
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.InstrumentationTestRunner
com.blundell.tut.test.MyTests:......
com.blundell.tut.test.MyOtherTests:..........
Test results for InstrumentationTestRunner=..................
Time: 15.295
OK (20 tests)
$ adb -s emulator-5580 emu event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0
@Override
public 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 -prop
persist.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 5580
network status
Current network status:
download speed: 14400 bits/s (1.8 KB/s)
upload speed: 14400 bits/s (1.8 KB/s)
minimum latency: 150 ms
maximum latency: 550 ms
OK
kextstat | grep intel
$ adb -e shell monkey -p com.blundell.tut -v -v 1000
Events 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 1080
tap 150 200
# monkey
tap 200 200 # Touch and select the edit text input
type HelloWorld # Type Hello World
tap 200 350 # Tap the button to show the toast
tap 200 200 # Touch and select the edit text again
press DEL # delete the text
press DEL
press DEL
press DEL
press DEL
type Monkey # Type Monkey
tap 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 monkeyrunner
import 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 object
device = 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 screenshot
MonkeyRunner.sleep(3.0)
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('/tmp/device.png')
device.press('KEYCODE_BACK', 'DOWN'_AND_UP')
$ monkey_playback.py script.mr