gpt4 book ai didi

java - 程序类型已经存在 : androidx. test.InstrumentationRegistry

转载 作者:行者123 更新时间:2023-11-29 00:51:56 25 4
gpt4 key购买 nike

尝试运行下面的测试时,我不断收到一条错误消息:'程序类型已经存在:androidx.test.InstrumentationRegistry'

我是新的 android 程序员,我不确定出了什么问题。我在网上读到 androidTestImplementation 的顺序很重要但是当移动它时没有任何反应。我仍然遇到同样的错误。我也尝试清理构建然后重建项目,但错误仍然存​​在。

提前感谢您的帮助:)

@RunWith(MockitoJUnitRunner.class)
public class ExampleInstrumentedTest {

@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("com.testing", appContext.getPackageName());
}



}
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.testing"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/Product_Selection_layouts'] } }
testOptions {
unitTests.returnDefaultValues = true
}
}

dependencies {
implementation 'org.jsoup:jsoup:1.12.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation 'androidx.recyclerview:recyclerview:1.0.0'

// androidTestImplementation 'com.android.support.test:runner:1.0.2'


//For bottom navigation
//noinspection GradleCompatible
implementation 'com.android.support:design:27.0.2'
implementation files('libs/mockito-core-2.1.0.jar')

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
testImplementation 'org.mockito:mockito-core:2.13.0'

androidTestImplementation 'androidx.test:runner:1.2.0'

androidTestImplementation 'com.android.support:support-annotations:28.0.0'

}


最佳答案

我刚刚得到答案,按此顺序排列它们使我的工作正常。这必须在依赖项中。

    androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'

关于java - 程序类型已经存在 : androidx. test.InstrumentationRegistry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58662883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com