Why android studio automatically only support ONE test file?


I wanted to add two different test files in my project. One for instrumental tests and the other one for junit tests.

I have added src/androidTest/java file into my project. Everything worked perfectly, java file changed its color to green, but when I added src/test/java it didn’t work. The file appears in gold(?) and it is not reconised automatically by the IDE.

I thought it was a problem of gradle configuration and I tried to reconfigure the build.gradle and it didn’t work.

So I started from a clean branch and added, firstly, the file /src/test/java to see what was going to happend. It worked. It was green. But I couldn’t add /src/androidTest/java, because it was not reconized. Why is this happening? Can I have both files at the same time?




Tap on the “Build Variants” view, docked by default on the left side of your Android Studio window.

You will see, towards the top, a drop-down entitled “Test Artifact”. Your choices there are “Android Instrumentation Tests” and “Unit Tests”. This controls whether androidTest/ or test/ is being actively managed by the IDE at this point in time. This is reminiscent of how Android Studio handles other sourcesets — whatever you have chosen in Build Variants will have “real” directories, while other build variants will have unrecognized directories.

My understanding is that there is hope that this can be improved in the future, though my guess is that this will require changes to IntelliJ IDEA, from which Android Studio inherits.

Answered By – CommonsWare

Leave a Comment