Сбой теста эспрессо с «Конфликт с зависимостью» - PullRequest
0 голосов
/ 18 ноября 2018

Я просто хотел начать интеграцию некоторых базовых тестов моего приложения, используя «Record Espresso test» в Android Studio версии 3.2.1.Я могу записать тест.После этого Studio подсказывает мне, что некоторые зависимости отсутствуют, и нужно ли их добавлять.Здесь я выбираю да.Gradle снова хочет синхронизироваться, и этот процесс завершается без каких-либо проблем.Если я сейчас хочу запустить один из тестов, начнется процесс сборки.Это терпит неудачу с

Conflict with dependency 'androidx.annotation:annotation' in project ':app'. Resolved versions for app (1.0.0-rc01) and test app (1.0.0) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

Я посмотрел на предоставленную ссылку, но это на самом деле не дает мне больше.

Может кто-нибудь направить меня в правильном направлении, что я делаю неправильно?

Результат "androidDependencies" слишком длинный, чтобы добавить его к моему вопросу из-за ограничения в 30000 символов.

Мое приложение для Android Gradle файл

apply plugin: 'com.android.application'

project.ext.appPlayStoreVersion = 68
project.ext.appVersion = '1.8.2'
project.ext.appLabel = 'FreightWeight'

project.ext.compileSdk = 28
project.ext.minSdk = 21
project.ext.targetSdk = 28

project.ext.firebase_version = '16.0.1'
project.ext.firebase_ui_version = '2.1.1'
project.ext.support_library_version = '27.1.1'
project.ext.buildTools = '28.0.3'
project.ext.multidex_version = '1.0.1'
project.ext.glide_version = '3.7.0'
project.ext.constraints_version = '1.0.2'

// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))


android {
    signingConfigs {
        configRelease {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    compileSdkVersion compileSdk
    defaultConfig {
        applicationId "de.mobacomp.android.freightweight"
        minSdkVersion minSdk
        targetSdkVersion targetSdk
        versionCode appPlayStoreVersion
        versionName "$appVersion"
        // Enabling multidex support.
        multiDexEnabled false
        resValue "string", "app_version_name", versionName
        signingConfig signingConfigs.configRelease
        testInstrumentationRunner = 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled true
            resValue "string", "app_name", appLabel
            resValue "string", "mobile_ads_id", "ca-app-pub-xyz"
            resValue "string", "ad_unit_banner_1", "ca-app-pub-xyz"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.configRelease
            resValue "string", "APP_FILEPROVIDER", defaultConfig.applicationId + ".release" + ".fileprovider"
            // lets generate a proper file name
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def fileName = applicationId + "-v" + appVersion + "_" + versionCode + ".apk"
                    outputFileName = new File("release", fileName)

                }
            }
        }
        debug {
            minifyEnabled false
            resValue "string", "app_name", "FW-debug"
            resValue "string", "mobile_ads_id", "ca-app-pub-xyz"
            resValue "string", "ad_unit_banner_1", "ca-app-pub-xyz"
            applicationIdSuffix ".debug"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.configRelease
            resValue "string", "APP_FILEPROVIDER", defaultConfig.applicationId + ".debug" + ".fileprovider"
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        jumboMode true
    }
    productFlavors {
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'

    // GLide
    implementation "com.github.bumptech.glide:glide:$glide_version"

    // Firebase stuff
    implementation "com.firebaseui:firebase-ui-database:4.2.1"
    implementation "com.firebaseui:firebase-ui-auth:4.2.1"
    implementation "com.google.firebase:firebase-core:16.0.5"
    implementation "com.google.firebase:firebase-database:16.0.5"
    implementation "com.google.firebase:firebase-storage:16.0.5"
    implementation "com.google.firebase:firebase-auth:16.0.5"

    implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
    implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'

    // Google Play stuff
    implementation "com.google.android.gms:play-services-auth:16.0.1"
    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation "com.google.android.gms:play-services-analytics:16.0.5"
    implementation "com.google.android.gms:play-services-cast-framework:16.1.0"
    implementation 'com.google.gms:google-services:4.1.0'

    implementation "com.android.support:preference-v14:28.0.0"
    implementation "com.android.support:mediarouter-v7:28.0.0"
    implementation "com.android.support:design:28.0.0"
    implementation "com.android.support:customtabs:28.0.0"
    implementation "com.android.support:cardview-v7:28.0.0"
    implementation "com.android.support:recyclerview-v7:28.0.0"
    implementation "com.android.support:support-v4:28.0.0"
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation "com.android.support:palette-v7:28.0.0"
    implementation "com.android.support.constraint:constraint-layout:1.1.3"
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'
}



apply plugin: 'com.google.gms.google-services'

Инаконец, короткий тест, который я записал (пробовал и более длинные, тоже самое)

package de.mobacomp.android.freightweight;


import androidx.test.espresso.ViewInteraction;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class MainFragmentActivityTest {

    @Rule
    public ActivityTestRule<MainFragmentActivity> mActivityTestRule = new ActivityTestRule<>(MainFragmentActivity.class);

    @Test
    public void mainFragmentActivityTest() {
        // Added a sleep statement to match the app's execution delay.
        // The recommended way to handle such scenarios is to use Espresso idling resources:
        // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
        try {
            Thread.sleep(7000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ViewInteraction button = onView(
                allOf(withId(R.id.buttonContinueStartApp),
                        childAtPosition(
                                childAtPosition(
                                        IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
                                        0),
                                1),
                        isDisplayed()));
        button.check(matches(isDisplayed()));

        ViewInteraction button2 = onView(
                allOf(withId(R.id.buttonContinueStartApp),
                        childAtPosition(
                                childAtPosition(
                                        IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
                                        0),
                                1),
                        isDisplayed()));
        button2.check(matches(isDisplayed()));

        // Added a sleep statement to match the app's execution delay.
        // The recommended way to handle such scenarios is to use Espresso idling resources:
        // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ViewInteraction overflowMenuButton = onView(
                allOf(withContentDescription("More options"),
                        childAtPosition(
                                childAtPosition(
                                        withId(R.id.action_bar),
                                        2),
                                0),
                        isDisplayed()));
        overflowMenuButton.perform(click());

        // Added a sleep statement to match the app's execution delay.
        // The recommended way to handle such scenarios is to use Espresso idling resources:
        // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ViewInteraction appCompatTextView = onView(
                allOf(withId(R.id.title), withText("Datenschutz Hinweise"),
                        childAtPosition(
                                childAtPosition(
                                        withId(R.id.content),
                                        0),
                                0),
                        isDisplayed()));
        appCompatTextView.perform(click());

        pressBack();

        // Added a sleep statement to match the app's execution delay.
        // The recommended way to handle such scenarios is to use Espresso idling resources:
        // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ViewInteraction overflowMenuButton2 = onView(
                allOf(withContentDescription("More options"),
                        childAtPosition(
                                childAtPosition(
                                        withId(R.id.action_bar),
                                        2),
                                0),
                        isDisplayed()));
        overflowMenuButton2.perform(click());

        // Added a sleep statement to match the app's execution delay.
        // The recommended way to handle such scenarios is to use Espresso idling resources:
        // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ViewInteraction appCompatTextView2 = onView(
                allOf(withId(R.id.title), withText("Settings"),
                        childAtPosition(
                                childAtPosition(
                                        withId(R.id.content),
                                        0),
                                0),
                        isDisplayed()));
        appCompatTextView2.perform(click());

        ViewInteraction linearLayout = onView(
                allOf(childAtPosition(
                        allOf(withId(R.id.recycler_view),
                                childAtPosition(
                                        withId(android.R.id.list_container),
                                        0)),
                        1),
                        isDisplayed()));
        linearLayout.perform(click());

        ViewInteraction linearLayout2 = onView(
                allOf(childAtPosition(
                        allOf(withId(R.id.recycler_view),
                                childAtPosition(
                                        withId(android.R.id.list_container),
                                        0)),
                        3),
                        isDisplayed()));
        linearLayout2.perform(click());

        ViewInteraction linearLayout3 = onView(
                allOf(childAtPosition(
                        allOf(withId(R.id.recycler_view),
                                childAtPosition(
                                        withId(android.R.id.list_container),
                                        0)),
                        4),
                        isDisplayed()));
        linearLayout3.perform(click());
    }

    private static Matcher<View> childAtPosition(
            final Matcher<View> parentMatcher, final int position) {

        return new TypeSafeMatcher<View>() {
            @Override
            public void describeTo(Description description) {
                description.appendText("Child at position " + position + " in parent ");
                parentMatcher.describeTo(description);
            }

            @Override
            public boolean matchesSafely(View view) {
                ViewParent parent = view.getParent();
                return parent instanceof ViewGroup && parentMatcher.matches(parent)
                        && view.equals(((ViewGroup) parent).getChildAt(position));
            }
        };
    }
}

Вывод «androidDependencies» слишком большой, так что здесь есть ссылка на него. Ссылка на файл на моем веб-сервере

Удалено "com.google.gms: google-services: 4.1.0", как было предложено, без изменений.

Ответы [ 2 ]

0 голосов
/ 22 ноября 2018

Чтобы я мог пометить его как завершенное:

Я уже использовал рефакторинг для androidx в Studio некоторое время назад. Просто дайте ему снова запуститься, и он найдет еще 11 частей для преобразования, и тест начнется. Я предполагаю, что функция записи эспрессо-теста в Studio не конвертируется в androidx, поэтому создает противоречивую конфигурацию.

Так что теперь я могу записывать тесты эспрессо и хорошо компилировать.

Спасибо за помощь.

0 голосов
/ 18 ноября 2018

удалить implementation 'com.google.gms:google-services:4.1.0' это совершенно неправильно.

проблема может быть в том, что вы используете com.android.support с androidx.test, а также testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" - неправильный тестовый прогон для androidx.test.

Приложение

не имеет единственной зависимости androidx - за исключением, возможно, некоторого .jar в каталоге libs.запустите ./gradlew app:dependencies > ./dependencies.txt && gedit ./dependencies.txt, чтобы увидеть, откуда это устаревшее androidx.annotation:annotation:1.0.0-rc01.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...