Skip to content
coooldoggy.dev

Android App 테스트- adb명령어를 이용한 테스트

Android1 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 localhost
4
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 id
12
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 message
26
27version                  show version num
28
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 all
38
39forward --list           list all forward socket connections
40
41forward [--no-rebind] LOCAL REMOTE
42
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 connection
58
59forward --remove-all     remove all forward socket connections
60
61ppp TTY [PARAMETER...]   run PPP over USB
62
63reverse --list           list all reverse socket connections from device
64
65reverse [--no-rebind] REMOTE LOCAL
66
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 connection
78
79reverse --remove-all     remove all reverse socket connections from device
80
81
82
83file transfer:
84
85push [--sync] LOCAL... REMOTE
86
87     copy local files/directories to device
88
89     --sync: only push files that are newer on the host than the device
90
91pull [-a] REMOTE... LOCAL
92
93     copy files/dirs from device
94
95     -a: preserve file timestamp and mode
96
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 copy
102
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 stdin
114
115     -T: disable PTY allocation
116
117     -t: force PTY allocation
118
119     -x: disable remote exit codes and stdout/stderr separation
120
121emu COMMAND              run emulator console command
122
123
124
125app installation (see also `adb shell cmd package help`):
126
127install [-lrtsdg] [--instant] PACKAGE
128
129     push a single package to the device and install it
130
131install-multiple [-lrtsdpg] [--instant] PACKAGE...
132
133     push multiple APKs to the device for a single package and install them
134
135install-multi-package [-lrtsdpg] [--instant] PACKAGE...
136
137     push one or more packages to the device and install them atomically
138
139     -r: replace existing application
140
141     -t: allow test packages
142
143     -d: allow version code downgrade (debuggable packages only)
144
145     -p: partial application install (install-multiple only)
146
147     -g: grant all runtime permissions
148
149     --instant: cause the app to be installed as an ephemeral install app
150
151     --no-streaming: always push APK to device and invoke Package Manager as separate steps
152
153     --streaming: force streaming APK directly into Package Manager
154
155     --fastdeploy: use fast deploy
156
157     --no-fastdeploy: prevent use of fast deploy
158
159     --force-agent: force update of deployment agent when using fast deploy
160
161     --date-check-agent: update deployment agent when local version is newer and using fast deploy
162
163     --version-check-agent: update deployment agent when local version has different version code and using fast deploy
164
165     --local-agent: locate agent files from local source build (instead of SDK location)
166
167uninstall [-k] PACKAGE
168
169     remove this app package from the device
170
171     '-k': keep the data and cache directories
172
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 transport
192
193logcat                   show device log (logcat --help for more)
194
195
196
197security:
198
199disable-verity           disable dm-verity checking on userdebug builds
200
201enable-verity            re-enable dm-verity checking on userdebug builds
202
203keygen FILE
204
205     generate adb public/private key; private key stored in FILE,
206
207
208
209scripting:
210
211wait-for[-TRANSPORT]-STATE
212
213     wait for device to be in the given state
214
215     State: device, recovery, sideload, or bootloader
216
217     Transport: usb, local, or any [default=any]
218
219get-state                print offline | bootloader | device
220
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 will
228
229      will automatically reboot the device.
230
231reboot [bootloader|recovery|sideload|sideload-auto-reboot]
232
233     reboot the device; defaults to booting system image but
234
235     supports bootloader and recovery too. sideload reboots
236
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 package
242
243root                     restart adbd with root permissions
244
245unroot                   restart adbd without root permissions
246
247usb                      restart adbd listening on USB
248
249tcpip PORT               restart adbd listening on TCP on PORT
250
251
252
253internal debugging:
254
255start-server             ensure that there is a server running
256
257kill-server              kill the server if it is running
258
259reconnect                kick connection from host side to force reconnect
260
261reconnect device         kick connection from device side to force reconnect
262
263reconnect offline        reset offline/unauthorized devices to force reconnect
264
265
266
267environment variables:
268
269$ADB_TRACE
270
271     comma-separated list of debug info to log:
272
273     all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
274
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

이렇게 명령하면 터치횟수만으로 이루어진 테스트를 실행하는 것이다.