Skip to content Skip to sidebar Skip to footer

Cannot Create Testing Folders In Android Studio

I have a project where I have created both a Java and an Android library. Within the Android library, a testing folder was created, see below: However, I want to add testing in t

Solution 1:

Android gradle setup follows the standard maven folder structure, i.e, src/main/java, src/test/java, etc...

Your production code will go into src/main/java, Your JVM unit test code goes into src/test/java, Your tests that needs Android device goes into src/androidTest/java.

These are standard folder names. Gradle be default recognizes these folder names. If you need to provide your own folder names (you should try to avoid these), you need to add the below config in your build.gradle.

android {
    sourceSets {
        androidTest.java.srcDirs += "src/androidEndpointTest/java"
    }
}

Now, inside the src/main/java or src/androidTest/java you can create any Java file you want. But you cant have the same Java file with the same package inside both src/main/java and src/androidTest/java. For example, you can't have src/main/java/com/example/SomeFile.java and src/androidTest/java/com/example/SomeFile/java. This is because Gradle will merge these folders during running tests, and you can't have two files with same name in the same folder.

Post a Comment for "Cannot Create Testing Folders In Android Studio"