Android Test #1

Jae-young Lee
Jul 25, 2017 · 5 min read

Android application 을 개발할 때 사용할 수 있는 Unit test 는 두가지 방법이 있습니다.

Local Unit Tests

module-name/src/test/java/.

Local JVM 기반으로 동작하기 때문에, Mockito 와 같은 Framework 을 통해 Android framework 에 종속성이 없거나, mock 형태로 제공할 수 있는 간단한 기능을 Test 합니다.

Testing with Dagger 설명처럼 Unit test 에는 DI 를 삽입하지 않으며, Local JVM 기반이라 Network 을 통한 json 도 mock 형태로 제공받아야 합니다. OkHttp 의 경우 MockWebServer 라는 형태로 제공합니다.

Instrumented Unit Tests

module-name/src/androidTest/java/.

Local JVM 이 아니라, 기기 혹은 AVD 기반으로 동작합니다. Instrumentation API 에 접근할 수 있고, Gradle flavor 도 사용할 수 있으며, DI 도 사용할 수 있습니다. 즉, Test 용 AndroidManifest.xml 을 사용할 수도 있고, 각종 Test DI Module 도 따로 가져갈 수 있으며, Context 에 접근도 가능합니다.

UI Tests

Instrumented Test 에서, Espresso 를 통한 UI 테스트도 가능합니다.

Testing Your Service and Content Provider

Automating UI Performance Tests

UI Automator

Integration Tests

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade