对于我正在使用的仪器测试
@RunWith(AndroidJUnit4.class)
Run Code Online (Sandbox Code Playgroud)
从
import androidx.test.runner.AndroidJUnit4;
Run Code Online (Sandbox Code Playgroud)
为了建立我的测试用例.现在,这条线被标记为与提示使用过时AndroidJUnit4的
import androidx.test.ext.junit.runners.AndroidJUnit4
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试AndroidJUnit4从命名包导入我得到错误,ext无法解决.
您是否有任何想法,应该在gradle中包含哪些包来解决此问题?
显然我需要正确的导入语句来解决这个问题.根据文档AndroidJUnit4,这应该是
import android.support.test.runner.AndroidJUnit4;
Run Code Online (Sandbox Code Playgroud)
当我这样做时,Android Studio突出显示runner为红色并抱怨"无法解析符号'跑步者'".
背景
我遵循Android开发者网站上的教程,使用UI Automator设置测试,从而达到了这一点.我遇到的第一个问题是,com.android.support:support-v4:22.2.0并com.android.support.test:runner:0.2依赖于不同的版本com.android.support:support-annotations.我按照Android漏洞报告的建议,allprojects在我的项目中添加了以下内容build.gradle:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
}
Run Code Online (Sandbox Code Playgroud)
这解决了即时错误,但我怀疑它导致了我当前的问题.有没有人有任何关于如何解决这个问题的建议?
从`./gradlew:app:dependencies中重新发布部分
androidTestCompile - Classpath for compiling the androidTest sources.
+--- com.jayway.android.robotium:robotium-solo:5.2.1
+--- com.squareup:fest-android:1.0.8
| \--- org.easytesting:fest-assert-core:2.0M10
| \--- org.easytesting:fest-util:1.2.5
+--- com.android.support.test:runner:0.2
| +--- junit:junit-dep:4.10
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- com.android.support.test:exposed-instrumentation-api-publish:0.2
| \--- com.android.support:support-annotations:22.0.0 -> 22.2.0
+--- com.android.support.test:rules:0.2
| \--- com.android.support.test:runner:0.2 (*)
\--- com.android.support.test.uiautomator:uiautomator-v18:2.1.0
compile - Classpath …Run Code Online (Sandbox Code Playgroud) android gradle build.gradle android-uiautomator testing-support-library
构建时我收到以下错误:
Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ.
Run Code Online (Sandbox Code Playgroud)
这些是我的gradle依赖项
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup:otto:1.3.8'
compile 'com.snappydb:snappydb-lib:0.5.2'
compile 'com.esotericsoftware.kryo:kryo:2.24.0'
compile 'com.google.dagger:dagger:2.0.1'
apt 'com.google.dagger:dagger-compiler:2.0.1'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'org.apache.commons:commons-lang3:3.4'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'
debugCompile …Run Code Online (Sandbox Code Playgroud) android gradle build.gradle android-gradle-plugin android-espresso