您的位置:首页 > 移动开发 > Android开发

android studio 单元测试问题记录

2017-01-18 16:42 309 查看

问题1:在Build Variants窗口中没有Test Artifact来选择测试器

如图:






解决方案是在Menu中依次打开: File ->
Settings ->
Build, Execution, Deployment ->
Build Tools -> Gradle ->
Experimental

Enable all test artifacts (Unit
Test and Instrumentation Test) in Android projects
取消勾选,点击OK后效果如下图







问题2:Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.3.0) and test app (23.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

在配置支持UI测试的时候首先添加
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
其次添加
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'
}
然后提示问题2,在dependencies中添加

androidTestCompile 'com.android.support:support-annotations:23.3.0'

总共添加的代码如下
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'
// Solves "versions for app (23.3.0) and test app (23.1.1) differ"
androidTestCompile 'com.android.support:support-annotations:23.3.0'
}
问题2解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息