06.1 UI Testing
06.1 UI Testing
Testing your
UI
Lesson 6
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation
'com.android.support.test.espresso:espresso-
core:3.0.1'
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
● Store in module-name/src/androidTests/java/
○ In Android Studio: app > java > module-name
(androidTest)
@Test
public void changeText_sameActivity() {
// 1. Find a View
// 2. Perform an action
// 3. Verify action was taken, assert
result
}
Result snippet
android.support.test.espresso.base.DefaultFailureHandler$Ass
ertionFailedWithCauseError: 'with text: is "This is a
failing test."' doesn't match the selected view.
Expected: with text: is "This is a failing test."
Got: "AppCompatTextView{id=2131427417, res-name=text_message
...
This work is licensed under a
Android Developer UI testing Creative Commons Attribution 4.0 30
Fundamentals V2 International License
Recording
tests
Videos
● Android Testing Support - Android Testing Patterns #1 (introduction)
● Android Testing Support - Android Testing Patterns #2 (onView view
matching)
● Android Testing Support - Android Testing Patterns #3 (onData &
adapter views)
This work is licensed under a
Android Developer UI testing Creative Commons Attribution 4.0 36
Fundamentals V2 International License
Learn even more