Espresso framework
1. Preparation
1.1 Dependency configuration
1.2 Eliminate interference
2. Espresso architecture
2.1 Positioning View (onView / onData)
2.2 [Operation View (perform)] (#Operation View)
2.3 [Assert View (check)] (# Assert View)
Preparation
Dependency configuration
1. Add dependencies
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1')
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation files('libs/mockito-core-2.21.0.jar')
testImplementation 'junit:junit:4.12'
2. Configure the test runner
Configure testIntrumentRunner in the defaultConfig area of the build.gradle file under the app module
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Eliminate interference
Under developer options, turn off some configurations that may affect the transition animation zoom window animation zoom animation program duration zoomEspresso architecture
Espresso has three important classes, namely Matchers, ViewAction, and ViewAssertions, where Matchers often need to find UI components or filter UI through matching conditions, and ViewAction is to simulate users The behavior of the operation interface, ViewAssertions transforms and validates the view that simulates the behavior operation1. Positioning View (onView / onData)
The class of positioning elements is com.android.support.test.espresso.Espresso. There are two methods onView () and onData () under this class to locate the name of the ordinary View method: com.android.support.test.espresso.Espresso.onVew ( ) Method declaration public static ViewInteraction onView (final MatcherLocate the View onData ()
method name of the adapter com.android.support.test.espresso.Espresso.onData ()
method declaration public static DataInteraction onData (Matcher <? Extends Object> dataMatcher)
positioning principle In a row in the
input parameter DataMatchers is used to express the ViewMatchers.instanceOf which is the View
class of inherited Adapter to be found
. . .
The return value DataInteraction represents the data set that can be manipulated android.support.test.espresso.DataInteraction
Second, operate the View (perform)
Perform an operation on an element (perform) ViewInteraction / DataInteraction perform () can be chained to call viewInteraction.perform (xx1) .perform (xx2) ...; parameter android.support.test.espresso.action.ViewActions common actions under the ViewActions tool class click (): Click operation typeText (): Enter text clearText (): Clear text replaceText (): Replace text. . .Three, assert View (check)
Three, judge the execution result check
check () method android.support.test.espresso.ViewInteraction.check ()
incoming parameters ViewAssertion ViewAssertions tool class
Four, thread synchronization
Fourth, thread synchronization
IddlingResoureces
https://developer.android.google.cn/reference/android/support/test/uiautomator/UiWatcher
References
https://www.jianshu.com/p/c5da84eae63b
https://www.jianshu.com/p/474f276986ac
https://blog.csdn.net/u013247461/article/details/81042763