Espresso is targeted at developers, who believe that automated testing is an integral part of the development lifecycle.html
Codename | API |
Froyo | 8 |
Gingerbread | 10 |
Ice Cream Sandwich | 15 |
Jelly Bean | 16, 17 ,18 |
KitKat | 19 |
Lollipop | 21 |
参考地址:https://google.github.io/android-testing-support-library/docs/espresso/index.htmlandroid
https://google.github.io/android-testing-support-library/docs/espresso/index.htmlgit
关于环境搭建的过程当中,我遇到了好几个问题也耗费了很长的时间。不过这一次总结的经验教训就是下一次若是有对应的sample project的时候,在我遇到困难的时候。必定要先download。对照sample 进行modify.这样会加快我解决问题的速度。github
关闭测试机三个选项。具体操做步骤以下:web
On your device, under Settings->Developer options disable the following 3 settings:api
Window animation scaleapp
Transition animation scale框架
Animator duration scalemaven
第一步:肯定SDK中已经下载了最新版的 Android Support Repository学习
以下图所示:
第二步:直接修改app下面的build.gradle文件,下载须要的jar包
下面的build.gradle文件,是个人项目中的,其中标注-----Espresso中要求添加的部分
就是Espresso须要添加的jar包。其中分为了必选项和可选项。根据须要进行选择添加
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.collection.self.com.espressotest" minSdkVersion 10 targetSdkVersion 23 versionCode 1 versionName "1.0" //-----Espresso中要求添加的部分(必选项) testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // testCompile 'junit:junit:4.12'----这个必定要删除,不然AndroidJUnit4没法下载下来 androidTestCompile 'com.android.support:support-annotations:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' // Android JUnit Runner-----Espresso中要求添加的部分(必选项) androidTestCompile 'com.android.support.test:runner:0.4.1' // JUnit4 Rules-----Espresso中要求添加的部分(必选项) androidTestCompile 'com.android.support.test:rules:0.4.1' // Espresso core-----Espresso中要求添加的部分(必选项) androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource //-----Espresso中要求添加的部分(可选项) androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1' // Espresso-web for WebView support-----Espresso中要求添加的部分(可选项) androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1' // Espresso-idling-resource for synchronization with background jobs-----Espresso中要求添加的部分(可选项) androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.1' }
https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSampleBundled/libs
参考地址:https://google.github.io/android-testing-support-library/downloads/index.html
报错内容以下:
Error:Conflict with dependency 'com.android.support:support-annotations'.
Resolved versions for app (23.1.1) and test app (23.0.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details.
解决方案以下:
在app/build.gradle中添加一个设置就能够了
androidTestCompile 'com.android.support:support-annotations:23.1.1'
这个在上面给出的build.gradle文件中已经贴出来了。
下面是对这个问题的英文解释:
Resolving conflicts between main and test APK
When instrumentation tests are run, both the main APK and test APK share the same classpath.
Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions.
If gradle didn't catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases).
To make the build succeed, just make sure both APKs use the same version.
If the error is about an indirect dependency (a library you didn't mention in your build.gradle),
just add a dependency for the newer version to the configuration ("compile" or "androidTestCompile") that needs it.
You can also use Gradle's resolution strategy mechanism.
You can inspect the dependency tree by running ./gradlew :app:dependencies and ./gradlew :app:androidDependencies.
(英文不是很好,就不翻译了)
报错内容以下:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException:
Duplicate files copied in APK META-INF/maven/com.google.guava/guava/pom.properties
File1: F:\workspace\UnitTestProject\app\build\intermediates\exploded-aar\com.android.support.test.espresso\espresso-web\2.2.1\jars\classes.jar
File2: F:\workspace\UnitTestProject\app\build\intermediates\exploded-aar\com.android.support.test.espresso\espresso-core\2.2.1\jars\classes.jar
解决方案以下:
在app/build.gradle文件中添加以下配置:
packagingOptions {
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
参考地址:
http://stackoverflow.com/questions/33800924/espresso-web-import-causes-duplicatefileexception
https://github.com/googlesamples/android-testing/blob/master/ui/espresso/WebBasicSample/app/build.gradle
Espresso没法import AndroidJUnit4
解决方案以下:
app/build.gradle文件中不可出现以下配置项
testCompile 'junit:junit:4.12'
必须添加以下红色部分标出的配置项
dedefaultConfig { applicationId "com.collection.self.com.espressotest" minSdkVersion 9 targetSdkVersion 23 versionCode 1 versionName "1.0" //-----Espresso中要求添加的部分(必选项) }