[英]android - Unresolved reference : all method in Espresso
使用Espresso時,我對這些錯誤感到困惑。
這是我的導入:
import android.os.SystemClock import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 import org.junit.runner.RunWith import android.support.test.espresso.Espresso import android.support.test.espresso.action.ViewActions import android.support.test.espresso.assertion.ViewAssertions.matches import android.support.test.espresso.matcher.ViewMatchers.* import org.junit.Rule import org.junit.Test import org.junit.Before import sayurbox.com.oms.view.LoginActivity import android.support.test.espresso.intent.Intents.intended import android.support.test.espresso.intent.Intents import android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent import sayurbox.com.oms.view.HomeActivity
我已經添加了所有依賴項:
testImplementation 'junit:junit:4.12' testImplementation 'org.robolectric:robolectric:4.0.2' testImplementation "org.robolectric:shadows-multidex:4.0.2" testImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' testImplementation 'com.android.support.test:runner:1.0.2' testImplementation 'com.android.support.test:rules:1.0.2' testImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
這是錯誤:
Unresolved reference: test Unresolved reference: junit Unresolved reference: AndroidJUnit4 Unresolved reference: Test Unresolved reference: assertEquals Unresolved reference: InstrumentationRegistry ...
所有參考文獻均未解決。 你能幫我嗎?
我已經找到了解決方案,因為我將測試放在默認的Instrumentation測試目錄中,因此我需要將Gradle的“ testImplementation”語法更改為“ androidTestImplementation”:
之前:
testImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' testImplementation 'com.android.support.test:runner:1.0.2' testImplementation 'com.android.support.test:rules:1.0.2' testImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
修復后:
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' androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.