Тип программы уже присутствует: androidx.test.InstrumentationRegistry - PullRequest
0 голосов
/ 01 ноября 2019

При попытке запустить тест ниже, я продолжаю получать сообщение об ошибке: «Тип программы уже существует: 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'

}


1 Ответ

0 голосов
/ 01 ноября 2019

Я только что получил ответ, приведение их в порядок заставило меня работать. Это должно быть в зависимостях.

    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'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...