簡體   English   中英

濃縮咖啡測試-Android

[英]Espresso Testing - Android

我在Android Espresso測試中遇到問題。 我似乎無法訪問“ AndroidJUnit4.class”。 下面的代碼將“ @RunWith(AndroidJUnit4.class)”作為“無法解析符號AndroidJUnit4 ”。

import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;    

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

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);

    @Test
    public void listGoesOverTheFold() {
        onView(withText("Hello world!")).check(matches(isDisplayed()));
    }
}

我知道這與build.gradle文件設置有關,但我不知道怎么了。 下面是我正在使用的副本。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "example.com.myapp"
        minSdkVersion 22
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'

    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    compile project(':volleylibrarygitpull')
}

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}

如果有人可以告訴我我的build.gradle文件有什么問題以便我使用Espresso測試框架,我將不勝感激。 我需要支持材料設計,因此比具有cardview的23.0.1更低的API級別, recyclerview將可以。

根據https://guides.codepath.com/android/UI-Testing-with-Espresso

您正在嘗試將測試放在錯誤的文件夾中,這就是Android Studio無法識別JUnit4類的原因。 閱讀上面的教程以使用androidTest文件夾。

還要注意,您為同一庫的模塊使用了不同的版本:

androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM