Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - Unresolved reference : all method in Espresso

I'm so confused with these error while using Espresso.

This is my import :

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

I already add all of the dependencies :

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'

This is the errors :

Unresolved reference: test
Unresolved reference: junit
Unresolved reference: AndroidJUnit4
Unresolved reference: Test
Unresolved reference: assertEquals
Unresolved reference: InstrumentationRegistry
...

All of the reference is unresolved. can you help me guys?

like image 856
Galih laras prakoso Avatar asked Nov 28 '18 11:11

Galih laras prakoso


1 Answers

I've found the solution, i think because i put my test in the default Instrumentation test directory so i need to change my Gradle 'testImplementation' syntax to 'androidTestImplementation' :

before :

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'

After fixed :

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'
like image 59
Galih laras prakoso Avatar answered Oct 14 '22 00:10

Galih laras prakoso