안드로이드 앱을 개발하면서 TDD를 적용하려고 시도했습니다.
TDD 자체는 실패했습니다. 이번에 한 일은 안드로이드 서비스 객체를 만드는 일이었는데, 서비스 객체를 담고 있는 앱과 사용자 시나리오가 시작되는 웹 브라우저와 데이터 저장이 일어나는 백엔드 서버를 동원하는 상황에서, 기능별 단위 테스트를 잡아내는 게 간단하지 않았습니다.
대신 단말 에뮬레이터에 기반한 e2e UI 테스트 자동화를 구현했습니다. 이를 통해 코너 케이스를 포함한 반복적인 테스트 업무를 자동화할 수 있었고, 개발 신뢰도와 생산성을 모두 높일 수 있었습니다.
e2e 테스트 도구, Appium
- UI 테스트 자동화를 위해 처음엔 Roboletric을 검토했으나 최종적으로 Appium을 쓰기로 결정함
- 앱, 웹 브라우저, 백엔드 서버가 모두 참여하는 e2e 테스트가 필요했기 때문
- e2e 테스트를 선택함으로써 "안드로이드 프레임워크 Mocking" 같은 번거로운 일에서 벗어나, "이 버튼을 누르면 이 영역에 이런 내용이 표시된다" 같은 사용자 관점의 테스트 시나리오 작성에 집중할 수 있었음
- e2e 테스트 과정에서 앱 화면, 안드로이드 OS 화면, 웹브라우저 화면을 조작해야 했음.
Appium inspect도구가 큰 도움됐음 - 팁1:
Appium inspect도구를 이용하면 앱 화면과 안드로이드 OS 화면에서 "이 버튼", "이 영역" 같은 화면 요소를 선택하기 위해 필요한 xpath 정보를 얻을 수 있음 - 팁2: 웹 화면 요소는 CSS selector로 지정할 수 있음
e2e 테스트의 숙명
- Appium은 활발하게 개발 중인 도구. 프로젝트 도중에 Appium이 버전업되면서 잘 실행되던 테스트 코드가 실패하는 문제를 자주 겪었음
- e2e 테스트의 숙명이라고 생각함
- e2e 테스트는 앱, 웹 브라우저, 백엔드 서버 같은 외부 컴포넌트에 의존하기 때문에 (심지어 Appium 같은 테스트 프레임워크에도 의존하기 때문에) 타의에 의해 테스트 코드가 실패할 수 밖에 없음. 그럴때마다 손을 봐야 함
appium과 uiautomator2 드라이버 설치 스크립트
Appium 설치 과정
❯ node -v
v20.19.5
❯ npm install -g appium
❯ appium -v
3.1.0
❯ appium driver install uiautomator2
❯ appium driver update uiautomator2 ## 드라이버 업데이트 (필요할 때만)
Appium은 테스트 프레임워크이고 uiautomator2 는 안드로이드를 위한 driver임
설치가 끝나면 Appium과 uiautomator2 드라이버가 정상 동작하는지 확인할 필요가 있음
appium driver doctor명령으로 정상 동작 여부를 확인할 수 있음- 마지막에
Bye! All issues have been fixed!가 출력되면 합격 - JAVA_HOME 환경변수와 ANDROID_HOME 환경변수를 적절히 설정하면 패스할 수 있었음
❯ appium driver doctor uiautomator2
Running 7 doctor checks for the "uiautomator2" driver
info Doctor ### Starting doctor diagnostics ###
info Doctor ✔ ANDROID\_HOME is set to: /Users/1109320/Library/Android/sdk
info Doctor Checking adb, emulator
info Doctor 'adb' exists in /Users/1109320/Library/Android/sdk/platform-tools/adb
info Doctor 'emulator' exists in /Users/1109320/Library/Android/sdk/emulator/emulator
info Doctor ✔ adb, emulator exist in '/Users/1109320/Library/Android/sdk'
info Doctor ✔ JAVA\_HOME is set to: /opt/homebrew/opt/openjdk@17
info Doctor ✔ 'bin/java' exists under '/opt/homebrew/opt/openjdk@17'
WARN Doctor ✖ bundletool.jar cannot be found
info Doctor ✔ ffmpeg exists at '/opt/homebrew/bin/ffmpeg'
WARN Doctor ✖ gst-launch-1.0 and/or gst-inspect-1.0 cannot be found
info Doctor ### Diagnostic completed, 0 required fixes needed, 2 optional fixes possible. ###
info Doctor
info Doctor ### Optional Manual Fixes ###
info Doctor To fix these optional issues, please do the following manually:
WARN Doctor ➜ bundletool.jar is used to handle Android App bundles. Please download the binary from [https://github.com/google/bundletool/releases/](https://github.com/google/bundletool/releases/) and store it to any folder listed in the PATH environment variable. Folders that are currently present in PATH: /Users/1109320/Library/Android/sdk/platform-tools:/opt/homebrew/opt/openjdk@17/bin:/Users/1109320/.nvm/versions/node/v20.19.5/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/opt/homebrew/bin:/Users/1109320/.local/bin:/platform-tools:/opt/homebrew/opt/openjdk@17/bin:/Users/1109320/.nvm/versions/node/v20.19.5/bin:/Applications/iTerm.app/Contents/Resources/utilities
WARN Doctor ➜ gst-launch-1.0 and gst-inspect-1.0 are used to stream the screen of the device under test. Please read [https://gstreamer.freedesktop.org/documentation/installing/index.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/installing/index.html?gi-language=c).
info Doctor
info Doctor Bye! All issues have been fixed!
info Doctor
Ref.
(이상입니다)






