【问题标题】:android - Unresolved reference : all method in Espressoandroid - 未解决的参考:Espresso 中的所有方法
【发布时间】:2019-04-30 06:49:23
【问题描述】:

我在使用 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
...

所有引用都未解析。你们能帮帮我吗?

【问题讨论】:

  • implementation vs testImplementation?那么你的java文件在哪里呢?
  • app -> src -> androidTest -> java -> mypackagename.com.oms -> 这里

标签: android android-espresso


【解决方案1】:

我找到了解决方案,我想是因为我将测试放在默认的 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'

【讨论】:

    猜你喜欢
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    • 2021-11-05
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多