[关闭]
@mSolo 2015-04-16T05:48:26.000000Z 字数 3780 阅读 1717

Android 测试学习笔记(三)

Android 测试 TDD 持续集成


管理测试环境

Headless emulator

$ emulator -avd testdevice -no-window -no-audio -no-boot-anim -port 5580

  1. $ adb -s emulator-5580 install YourApp.apk
  2. $ adb -s emulator-5580 shell am instrument -w\
  3. com.blundell.tut.test/android.test.InstrumentationTestRunner
  4. com.blundell.tut.test.MyTests:......
  5. com.blundell.tut.test.MyOtherTests:..........
  6. Test results for InstrumentationTestRunner=..................
  7. Time: 15.295
  8. OK (20 tests)
  1. @Override
  2. public void setUp() throws Exception {
  3. Activity activity = getActivity();
  4. Window window = activity.getWindow();
  5. window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  6. }
  1. $ emulator -avd testdevice -no-window -no-audio -no-boot-anim -port 5580 -prop
  2. 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

  1. $ telnet localhost 5580
  2. network status
  3. Current network status:
  4. download speed: 14400 bits/s (1.8 KB/s)
  5. upload speed: 14400 bits/s (1.8 KB/s)
  6. minimum latency: 150 ms
  7. maximum latency: 550 ms
  8. OK

加速模拟器

运行 Monkey

命令行方式

  1. $ adb -e shell monkey -p com.blundell.tut -v -v 1000
  2. Events injected: 1000
  3. :Sending rotation degree=0, persist=false
  4. :Dropped: keys=0 pointers=4 trackballs=0 flips=0 rotations=0
  5. ## Network stats: elapsed time=2577ms (0ms mobile, 0ms wifi, 2577ms not connected)
  6. // Monkey finished

客户/服务器方式

  1. $ adb -e shell monkey -p com.blundell.tut --port 1080 &
  2. $ adb -e forward tcp:1080 tcp:1080
  3. $ telnet localhost 1080
  4. tap 150 200
  1. # monkey
  2. tap 200 200 # Touch and select the edit text input
  3. type HelloWorld # Type Hello World
  4. tap 200 350 # Tap the button to show the toast
  5. tap 200 200 # Touch and select the edit text again
  6. press DEL # delete the text
  7. press DEL
  8. press DEL
  9. press DEL
  10. press DEL
  11. type Monkey # Type Monkey
  12. tap 200 350 # Tap the button to show the toast Hello Monkey
  1. $ adb shell am start -n com.blundell.tut/.MonkeyActivity
  2. $ nc localhost 1080 < ch_4_code_ex_10.txt

使用 monkeyrunner

示例(Getting test screenshots)

  1. #! /usr/bin/env monkeyrunner
  2. import sys
  3. # Imports the monkeyrunner modules used by this program from com.android.monkeyrunner
  4. # import MonkeyRunner, MonkeyDevice, MonkeyImage
  5. # Connects to the current device, returning a MonkeyDevice object
  6. device = MonkeyRunner.waitForConnection()
  7. if not device:
  8. print >> sys.stderr, "Couldn't" "get connection"
  9. sys.exit(1)
  10. device.startActivity(component='com'.blundell.tut/.MonkeyActivity')
  11. MonkeyRunner.sleep(3.0)
  12. device.type("hello")
  13. # Takes a screenshot
  14. MonkeyRunner.sleep(3.0)
  15. result = device.takeSnapshot()
  16. # Writes the screenshot to a file
  17. result.writeToFile('/tmp/device.png')
  18. device.press('KEYCODE_BACK', 'DOWN'_AND_UP')

录制和回放

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注