개발정보/안드로이드
안드로이드 개발 레벨업 교과서 8장 UI Test
dev김
2019. 1. 15. 19:03
테스트
unit test Junit
https://github.com/junit-team/junit/wiki/Getting-started
ui 테스트 개발중인 앱
Robolectric https://robolectric.org 안드로이드 sdk 에뮬레이트해서 테스트 진행
https://codelabs.developers.google.com/codelabs/android-testing/index.html?index=..%2F..index#6
Mockito https://mockito.org
onView(withId(editId)).perform(typeText("text")); onView(withId(btnId)).perform(perform(click()); onView(withText("text")).check(matches(isDisplayed()); @Rule public ActivityTestRule<MainActivity> mMainActivityTestRule = new ActivityTestRule<>(MainActivity.class); @Test onView(withText("message")).check(doesNotExist()); @Test onView(withId(fabId)).perform(click()); onView(withText("message")).check(matches(isDisplayed());
UI테스트 에스프레소 gradlew connectedAndroidTest
androidTestImplementation('com.android.support.test:runner:0.4') { exclude module: 'support-annotations' } androidTestImplementation('com.android.support.test:rules:0.4') { exclude module: 'support-annotations' } androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.1') { exclude module: 'support-annotations' }
exclude moduel 라이브러리 중복으로 인해 충돌시 설정
에스프레소 치트 시트
https://developer.android.com/training/testing/espresso/cheat-sheet
https://github.com/googlesamples/android-topeka/tree/java
Espresso.onView / Espresso.onData / Intents.intended / Intents.intending
UIautomator 다른 앱과의 연계 홈 화면에서의 동작 테스트
exclude 제외하고 러너와 룰러도 사용
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
https://developer.android.com/training/testing/ui-automator#java
$ANDROID_HOME/tools/uiautomatorviewer
단위 테스트는 가능한한 모두 UI테스트는 중요 화면과 기능으로 범위를 좁혀 작성