Search code examples
android-studiogradleandroid-gradle-pluginandroid-testing

Why would androidTest not show as a directory type in the dropdown for New Directory?


When I create a new directory in the src folder, I see test directory options, but I don't see options for creating androidTest directories. I do see androidTest directory options on my other machine on another app. What controls this?

This project has custom buildTypes. Could that be related?

Also, if I create the directory named androidTest, it's not recognized as an androidTest directory.

I have androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.6.1"

I don't think they would, but could it be missing because my company blocks it?


Solution

  • The issue was very difficult to determine but the solution is very simple. I wasn't aware that by default Android Instrumentation Tests are configured to only run on the 'Debug' variant. Since my application doesn't have a 'Debug' variant, resources in the androidTest folder did not appear to be recognized as test resources. By adding the 'testBuildType' setting (below) to my build.gradle:app file, the build variant used for development started recognizing instrumentation tests in the folder.

    android {
        testBuildType "buildVariantName"
    }