Espresso setup
instructions
- Setup your test environment
- Download Espresso
- Set the instrumentation runner
- Example build.gradle file
이 가이드는 SDK Manager를 이용해 Espresso 를 설치하고 Gradle을 이용해 빌드하는 것을 포함한다. 안드로이드 스튜디오를 추천한다.
Setup
your test environment
flakiness를 피하기 위해 테스트에 사용되는 가상 장치나 단말 장치의 system animation을 끌 것을 추천한다.
- 장치에서 설정->개발자 옵션-> 아래 세개의 셋팅을 비활성화한다:
- 창 애니메이션 배율
- 전환 애니메이션 배율
- Animator 길이 배율
Download
Espresso
- 최신 Android Support Repository under Extras 를 설치해야 한다. ( instructions을 보아라).
- 앱의 build.gradle 파일을 열어라. 보통 최상위 레벨의 build.gradle 파일이 아닌 app/build.gradle 파일이다.
- dependencies 에 다음 라인을 추가해라:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
- 더 많은 결과물은 downloads 섹션을 보아라(espresso-contrib, espresso-web, etc.)
Set
the instrumentation runner
- 동일한 build.gradle 파일의 android.defaultConfig에 다음 라인을 추가해라:
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
Example
build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22"
compileSdkVersion 22
buildToolsVersion "22"
defaultConfig {
applicationId "com.my.awesome.app"
minSdkVersion 10
targetSdkVersion 22.0.1
versionCode 1
versionName "1.0"
applicationId "com.my.awesome.app"
minSdkVersion 10
targetSdkVersion 22.0.1
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
}
}
dependencies {
// App's dependencies, including test
compile 'com.android.support:support-annotations:22.2.0'
// App's dependencies, including test
compile 'com.android.support:support-annotations:22.2.0'
// Testing-only
dependencies
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
Analytics
각 새로운 릴리즈에 대해 올바른 길로 나아가고 있는지 확인하기 위해 test runner는 분석을 수집한다. 더 명확하게는, 각 호출을 위한 테스트 중에 애플리케이션의 패키지 명 꾸러미를 업로드 한다. 이는 우리가 에스프레소를사용하는 고유한 패키지의 수뿐만 아니라 사용량을 측정가능하게 한다. 만약 이 데이터가 업로드 되는 것을 원하지 않는 경우 test runner에 다음의 인수를 전달하여 옵션으로부터 제거할 수 있다:
disableAnalytics
"true" (see how to pass custom arguments
Add
the first test
안드로이드 스튜디오는 기본으로 src/androidTest/java/com.example.package/ 에 있는 테스트를 생성한다.
Rule을 사용하는 JUnit4 test 예제는 :
@RunWith(AndroidJUnit4.class)
@LargeTest
public class HelloWorldEspressoTest {
@LargeTest
public class HelloWorldEspressoTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
@Test
public void listGoesOverTheFold() {
onView(withText("Hello world!")).check(matches(isDisplayed()));
}
}
public void listGoesOverTheFold() {
onView(withText("Hello world!")).check(matches(isDisplayed()));
}
}
Running
tests
In
Android Studio
테스트 환경을 생성한다.
안드로이드 스튜디오에서:
안드로이드 스튜디오에서:
- Open Run menu -> Edit Configurations
- Add a new Android Tests configuration
- Choose a module
- Add a specific instrumentation runner:
android.support.test.runner.AndroidJUnitRunner
Run
the newly created configuration.
From
command-line via Gradle
Execute
./gradlew
connectedAndroidTest
댓글 없음:
댓글 쓰기