簡體   English   中英

AndroidTestCompile依賴項在導入中無法識別

[英]AndroidTestCompile dependencies not recognized in the imports

實際上,我的項目有單元測試。 所有這些都在/src/test/java/中配置。最近我需要在/src/androidTest/java添加檢測測試。 為此,我在build.gradle添加了espresso依賴build.gradle

dependencies {
    compile files('libs/pixlui-1-0-5.jar')
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar') {
        transitive = true
    }
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.google.android.gms:play-services-maps:7.3.0'
    compile 'com.google.android.gms:play-services-location:7.3.0'
    compile 'com.google.android.gms:play-services-gcm:7.3.0'

    compile 'com.loopj.android:android-async-http:1.4.5'
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile 'com.android.support:support-v4:20.+'
    compile 'ch.acra:acra:4.5.0'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
    compile 'com.squareup.picasso:picasso:2.3.4'
    provided 'com.squareup.dagger:dagger-compiler:1.2.+'
    compile 'com.squareup.dagger:dagger:1.2.+'
    compile 'com.google.guava:guava:15.0'
    compile 'com.facebook.android:facebook-android-sdk:3.23.0'
    compile 'com.mixpanel.android:mixpanel-android:4.5.3'
    compile 'com.google.maps.android:android-maps-utils:0.3+'

    // Testing dependencies
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.9.5"

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
        exclude module: 'support-annotations'
    }
}

之后我選擇了Build Variants - > Test Artifact - > Android Instrumentation Tests。

但是當我開始編碼時,沒有任何依賴項被識別:

“無法解析onView上的符號”,“無法解析符號ViewInteraction”等...

這是我的活動測試:

import android.support.test.espresso.Espresso.onView;
import android.test.ActivityInstrumentationTestCase2;

import com.wiffinity.easyaccess.R;

/**
 * Created by Javier on 05/06/2015.
 */
public class EntryActivityTest extends ActivityInstrumentationTestCase2<EntryActivity> {

    public EntryActivityTest() {
        super(EntryActivity.class);
    }

    @Override
    protected void setUp() throws Exception
    {
        super.setUp();
        getActivity();
    }

    public void testLoginButtonClicked(){
        onView();

        ViewInteraction entryBtn;
        entryBtn = onView(withId(R.id.entry_button));

        entryBtn.performClick();
    }
}

為什么Android Studio 1.2無法解決這些依賴關系? 我忘了配置什么嗎?

您可能需要重建項目。

在Android Studio中:

構建 - >重建項目。

如果它沒有幫助運行以下gradle任務(假設你有一個包裝器,你的模塊名稱是“app”):

./gradlew app:dependencies

並確保您的androidTest任務包含espresso依賴項。

更新:

有時重建項目並不能解決問題,唯一的解決方案是通過執行gradle assembleAndroidTest任務手動重建測試apk。

暫無
暫無

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

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