首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Espresso测试的正确依赖项是什么?

Espresso测试的正确依赖项是什么?
EN

Stack Overflow用户
提问于 2018-05-04 16:38:49
回答 3查看 3.2K关注 0票数 0

在不同的官方Android站点上,有关于如何设置Espresso测试的不同信息:

1) https://developer.android.com/training/testing/ui-testing/espresso-testing

代码语言:javascript
运行
复制
dependencies {
    // Other dependencies ...
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

2) https://developer.android.com/studio/test/

代码语言:javascript
运行
复制
dependencies {
    // Required for local unit tests (JUnit 4 framework)
    testCompile 'junit:junit:4.12'

    // Required for instrumented tests
    androidTestCompile 'com.android.support:support-annotations:24.0.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
}

3) https://developer.android.com/training/testing/espresso/setup

代码语言:javascript
运行
复制
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
  • 对于某些配置,我得到了库冲突((2)解释说,这是因为依赖关系需要相同的其他依赖关系,但版本不同)。
代码语言:javascript
运行
复制
- Even excluding with 

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', { exclude group: 'com.android.support', module: 'support-annotations' }可能帮不上忙。

  • 对于某些配置,我在导入android.support.test.rule.ActivityTestRule时出错
EN

回答 3

Stack Overflow用户

发布于 2018-05-04 16:38:49

第三条似乎行得通,不管排除与否-部分:

代码语言:javascript
运行
复制
dependencies {
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
}

看起来,对于较早的espresso版本(如2.2.2 ),android.support.test.rule.ActivityTestRule导入不需要单独的依赖项。

票数 0
EN

Stack Overflow用户

发布于 2018-06-03 17:23:46

意式咖啡是一种仪器测试。这些被放置在一个与单元测试不同的文件夹中。它们被保存在新的androidTest/java超级包中。因此,在使用依赖关系时要记住这一点。对于您需要使用的仪表测试

代码语言:javascript
运行
复制
androidTestImplementation

vs

代码语言:javascript
运行
复制
testImplementation

因此,假设您的Espresso测试类位于app->src->androidTest->java位置中,这应该可以:

代码语言:javascript
运行
复制
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
票数 0
EN

Stack Overflow用户

发布于 2020-04-23 08:35:54

对于可能会寻找这个的人来说,这是我用Cucumber + Espresso +Barista安装的build.gradle

代码语言:javascript
运行
复制
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.lomza.uitestsapp"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testApplicationId "com.lomza.uitestsapp.tests"
        testInstrumentationRunner "com.lomza.uitestsapp.tests.GroceriesAppAndroidTestRunner"
    }

    sourceSets {
        androidTest {
            assets {
                assets.srcDirs = ['src/androidTest/assets']
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation "io.cucumber:cucumber-android:4.4.1"
    androidTestImplementation('com.schibsted.spain:barista:3.3.0') {
        exclude group: 'org.jetbrains.kotlin'
    }
}

检查一下我的整个教程,看看它在起作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50179597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档