A reference project for all of those things you forgot how to do in Espresso!
This repository contains an example Android application and a number of helpful Espresso UI tests to act as a helpful reference. The Espresso Package Reference can be found here.
To use test execute the tests you will can execute using the gradle command: ./gradlew app:createDebugCoverageReport
or by building the tests with a test configuration in Android Studio.
-
Android Testing Library
dependencies { androidTestCompile 'com.android.support.test:testing-support-lib:0.1' }
-
Espresso 2.0 Core
dependencies { androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' }
-
Espresso 2.0 Contrib
dependencies { androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0' }
-
Jacocco Code Coverage
debug { testCoverageEnabled true }
Below is an example of theEspresso methods that have been used so far in the example application.
The onView(Matcher<View>)
method can accept Matchers to identify a View.
-
withText(String)
-
withId(int)
-
isDisplayed()
-
isEnabled()
-
isTouchable()
-
isChecked()
-
isNotChecked()
-
isAssignableFrom(Matcher)
-
withHint(int|String)
-
withParent(Matcher<T>)
-
isDescendentOfA(Matcher<T>)
-
withChild(Matcher<T>)
-
hasSibling(Matcher<T>)
-
hasDescendant(Matcher<T>)
-
allOf(Matcher<T> ...)
-
not(Object)
-
endsWith(String)
-
startsWith(String)
Actions are performed using the perform(ViewAction)
method.
-
click()
-
pressBack()
-
typeText(String)
-
clearText()
-
replaceText(String)
-
swipeLeft()
-
swipeRight()
-
swipeUp()
-
swipeDown()
-
closeSoftKeyboard()
-
hasContentDescription()
-
withContentDescription(String)
-
scrollTo()
Assertions are performed using the check(ViewAssertion)
method.
-
matches(Matcher<T>)
-
isLeftOf(Matcher)
-
isRightOf(Matcher)
-
isAbove(Matcher)
-
isBelow(Matcher)
-
isLeftAlignedWith(Matcher)
-
isRightAlignedWith(Matcher)
-
isTopAlignedWith(Matcher)
-
isRightAlignedWith(Matcher)
-
doesNotExist()
-
selectedDescendantsMatch(Matcher)
-
noEllipsizedText(Matcher)
-
selectedDescendantsMatch(Matcher)
-
noOverlaps(Matcher)
Below is a short list of the Widgets and Views that are tested in this Repository.
-
TextView
-
Button
-
EditText
-
Overflow Menu
-
App Drawer
-
ViewPager
-
Spinner
-
ProgressBar
-
ViewPager -
PagerTabStrip
-
Date and Time Widgets
- Idling Resources
The JaCoCo Coverage plugin has been included to demonstrate coverage reporting. The Code Coverage can be found in the following directory structure within the module you are testing build/outputs/reports/coverage/debug/index.html