问题
I was working with uiautomator 1.0.1 using eclispe and generating jar files and using in my setup. Can anyone point to appropriate source where I can get step by step procedure for switching to Uiautomator 2.0 with Android Studio.
回答1:
To use the Android Testing Support Library in your Gradle project, add these dependencies in your build.gradle file:
dependencies {
androidTestCompile 'com.android.support.test:runner:0.4'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
Also you need to set the JUnitRunner as the default test instrumentation runner in your Gradle project (UI Automator 2.0 uses android.support.test.runner.AndroidJUnitRunner instead of android.test.InstrumentationTestRunner).
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
For more details, follow the link here.
来源:https://stackoverflow.com/questions/39501931/working-with-uiautomator-2-0-and-android-studio-2-x