Abu Ruqaiyah
Abu Ruqaiyah

Reputation: 1546

androidTest not compiling, showing cannot resolve symbol

I'm trying to add instrumented test using Espresso in my android project.

I've added all necessary libs, besides adding AndroidJUnitRunner as the testInstrumentationRunner:

app -> build.gradle

But for some reason, the imports are not working in instrumented test file:

androidTest file

But the local test file is getting the imports properly:

local test file

I've also added junit as androidTestImplementation, but makes no difference:

androidTestImplementation 'junit:junit:4.12'

This is why I cannot run the test file.

If I run the file anyway, I get this error:

Process finished with exit code 1
Class not found: "com.mcp.shippax.MainActivityEspressoTest"Empty test suite.

I cannot understand why this is happening (numerous grade syncs/invalidate caches/restarts), when the setup is so straight and simple.

I don't remember making any project changes other than converting most of my source files to Kotlin, including the test files. But later I reverted the test files back to java again.

Upvotes: 3

Views: 2157

Answers (1)

I had the same issue. I've had various build types for dev and prod environments and what helped me, was to specify testBuildType like in this answer https://stackoverflow.com/a/34778780/9736105.

So something like this:

android {

    ...

    testBuildType "<my-build-type>"

    buildTypes {
        <my-build-type> {
            ...  
        }
        ....
    }
}

After I did that and set my build variant to that build type, I was able to resolve all dependecies.

Upvotes: 3

Related Questions