— Android — 1 min read
안드로이드 테스트에는 다음과 같은 방법이 있다.
1.txt파일을 밀어넣어서 스크립트대로 동작하게하기 2.adb 명령어를 통한 랜덤테스트 3.Junit 테스트를 작성하여 실행
지난 포스트에 이어 adb명령어를 이용한 랜덤테스트에 관해 적어보겠다.
adb명령어를 사용하려면 마찬가지로 Android sdk가 설치된 경로에서 command를 실행해야한다.
1cd /Users/usr/Library/Android/sdk
adb 에서 사용할 수 있는 option은 다음과 같다.
1global options:2
3-a listen on all network interfaces, not just localhost4
5-d use USB device (error if multiple devices connected)6
7-e use TCP/IP device (error if multiple TCP/IP devices available)8
9-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)10
11-t ID use device with given transport id12
13-H name of adb server host [default=localhost]14
15-P port of adb server [default=5037]16
17-L SOCKET listen on given socket for adb server [default=tcp:localhost:5037]18
19
20
21general commands:22
23devices [-l] list connected devices (-l for long output)24
25help show this help message26
27version show version num28
29
30
31networking:32
33connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]34
35disconnect [HOST[:PORT]]36
37 disconnect from given TCP/IP device [default port=5555], or all38
39forward --list list all forward socket connections40
41forward [--no-rebind] LOCAL REMOTE42
43 forward socket connection using:44
45 tcp:<port> (<local> may be "tcp:0" to pick any open port)46
47 localabstract:<unix domain socket name>48
49 localreserved:<unix domain socket name>50
51 localfilesystem:<unix domain socket name>52
53 dev:<character device name>54
55 jdwp:<process pid> (remote only)56
57forward --remove LOCAL remove specific forward socket connection58
59forward --remove-all remove all forward socket connections60
61ppp TTY [PARAMETER...] run PPP over USB62
63reverse --list list all reverse socket connections from device64
65reverse [--no-rebind] REMOTE LOCAL66
67 reverse socket connection using:68
69 tcp:<port> (<remote> may be "tcp:0" to pick any open port)70
71 localabstract:<unix domain socket name>72
73 localreserved:<unix domain socket name>74
75 localfilesystem:<unix domain socket name>76
77reverse --remove REMOTE remove specific reverse socket connection78
79reverse --remove-all remove all reverse socket connections from device80
81
82
83file transfer:84
85push [--sync] LOCAL... REMOTE86
87 copy local files/directories to device88
89 --sync: only push files that are newer on the host than the device90
91pull [-a] REMOTE... LOCAL92
93 copy files/dirs from device94
95 -a: preserve file timestamp and mode96
97sync [all|data|odm|oem|product_services|product|system|vendor]98
99 sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)100
101 -l: list but don't copy102
103
104
105shell:106
107shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]108
109 run remote shell command (interactive shell if no command given)110
111 -e: choose escape character, or "none"; default '~'112
113 -n: don't read from stdin114
115 -T: disable PTY allocation116
117 -t: force PTY allocation118
119 -x: disable remote exit codes and stdout/stderr separation120
121emu COMMAND run emulator console command122
123
124
125app installation (see also `adb shell cmd package help`):126
127install [-lrtsdg] [--instant] PACKAGE128
129 push a single package to the device and install it130
131install-multiple [-lrtsdpg] [--instant] PACKAGE...132
133 push multiple APKs to the device for a single package and install them134
135install-multi-package [-lrtsdpg] [--instant] PACKAGE...136
137 push one or more packages to the device and install them atomically138
139 -r: replace existing application140
141 -t: allow test packages142
143 -d: allow version code downgrade (debuggable packages only)144
145 -p: partial application install (install-multiple only)146
147 -g: grant all runtime permissions148
149 --instant: cause the app to be installed as an ephemeral install app150
151 --no-streaming: always push APK to device and invoke Package Manager as separate steps152
153 --streaming: force streaming APK directly into Package Manager154
155 --fastdeploy: use fast deploy156
157 --no-fastdeploy: prevent use of fast deploy158
159 --force-agent: force update of deployment agent when using fast deploy160
161 --date-check-agent: update deployment agent when local version is newer and using fast deploy162
163 --version-check-agent: update deployment agent when local version has different version code and using fast deploy164
165 --local-agent: locate agent files from local source build (instead of SDK location)166
167uninstall [-k] PACKAGE168
169 remove this app package from the device170
171 '-k': keep the data and cache directories172
173
174
175backup/restore:176
177 to show usage run "adb shell bu help"178
179
180
181debugging:182
183bugreport [PATH]184
185 write bugreport to given PATH [default=bugreport.zip];186
187 if PATH is a directory, the bug report is saved in that directory.188
189 devices that don't support zipped bug reports output to stdout.190
191jdwp list pids of processes hosting a JDWP transport192
193logcat show device log (logcat --help for more)194
195
196
197security:198
199disable-verity disable dm-verity checking on userdebug builds200
201enable-verity re-enable dm-verity checking on userdebug builds202
203keygen FILE204
205 generate adb public/private key; private key stored in FILE,206
207
208
209scripting:210
211wait-for[-TRANSPORT]-STATE212
213 wait for device to be in the given state214
215 State: device, recovery, sideload, or bootloader216
217 Transport: usb, local, or any [default=any]218
219get-state print offline | bootloader | device220
221get-serialno print <serial-number>222
223get-devpath print <device-path>224
225remount [-R]226
227 remount partitions read-write. if a reboot is required, -R will228
229 will automatically reboot the device.230
231reboot [bootloader|recovery|sideload|sideload-auto-reboot]232
233 reboot the device; defaults to booting system image but234
235 supports bootloader and recovery too. sideload reboots236
237 into recovery and automatically starts sideload mode,238
239 sideload-auto-reboot is the same but reboots after sideloading.240
241sideload OTAPACKAGE sideload the given full OTA package242
243root restart adbd with root permissions244
245unroot restart adbd without root permissions246
247usb restart adbd listening on USB248
249tcpip PORT restart adbd listening on TCP on PORT250
251
252
253internal debugging:254
255start-server ensure that there is a server running256
257kill-server kill the server if it is running258
259reconnect kick connection from host side to force reconnect260
261reconnect device kick connection from device side to force reconnect262
263reconnect offline reset offline/unauthorized devices to force reconnect264
265
266
267environment variables:268
269$ADB_TRACE270
271 comma-separated list of debug info to log:272
273 all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp274
275$ADB_VENDOR_KEYS colon-separated list of keys (files or directories)276
277$ANDROID_SERIAL serial number to connect to (see -s)278
279$ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
adb를 이용하여 테스트를 실행하려면 command 라인에 이렇게 실행한다.
1//패키지를 10000번 테스트 실행2adb shell monkey -p com.example.package 10000
이렇게 실행하면 정말 말그대로 원숭이가 누르는 것과 같은 monkey test가 실행된다. 터치, 드래그, 입력 등등이 모두 랜덤인데 이것의 횟수를 정해서 테스트를 할수도 있다.
1--pct-touch <percent> Touch event 발생 빈도 조절2--pct-motion <percent> 드래그 event 발생 빈도 조절3--pct-trackball <percent> 트랙볼 event 발생 빈도 조절4--pct-nav <percent> Navigation event 발생 빈도 조절5--pct-majornav <percent> Back, Home 버튼등의 major navigation event 발생 빈도 조절6--pct-syskeys <percent> System event 발생 빈도 조절 (Volume, home, end call 등)7--pct-appswitch <percent> 새로운 app. 실행 event 발생 빈도 조절8--pct-anyevent <percent> 기타 event 발생 빈도 조절
예를 들어
1adb shell monkey -p com.example.package 10000 --pct-touch 100
이렇게 명령하면 터치횟수만으로 이루어진 테스트를 실행하는 것이다.