3

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.

10
  • Are you putting your test file in test or androidTest folder? Commented Feb 13, 2019 at 6:31
  • @BachVu in androidTest obviously :-) pasteboard.co/I0VLPBz.png. Commented Feb 13, 2019 at 6:35
  • Then it won't work, what you are doing is unit test, create test file in test folder Commented Feb 13, 2019 at 6:43
  • Um.. why do u think it's unit test? and what should I do to make it instrumented test? Fyi.. I'm simply trying this: github.com/google-developer-training/… Commented Feb 13, 2019 at 6:50
  • Oh my bad, I'm messing it up. Now, from what I'm seeing, you might be missing this androidTestImplementation org.jetbrains.kotlin:kotlin-test-junit:.. Commented Feb 13, 2019 at 7:59

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Do anyone knows why ? Is there something specific to call ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.