Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 267
coder Avatar asked Oct 15 '25 03:10

coder


2 Answers

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"
}
like image 199
coder Avatar answered Oct 18 '25 04:10

coder


In the latest Android Studio (Koala), testBuildType is not needed for androidTest to show as a directory type in the dropdown for New Directory.

In one of project's existing modules, I needed to manually add androidTest (new modules have test and androidTest automatically upon creation). All I had to do is

  1. Right-click on the src folder within the module's directory.
  2. Select New > Directory.
  3. Select androidTest\java from the dropdown that pops up:

dropdown for New Directory

like image 29
sfinja Avatar answered Oct 18 '25 02:10

sfinja