Looks like this feature is no longer supported in new iterations of the Android Studio IDE and IntelliJ platforms.
Edit: Sharing code this way no longer works. BUT, there is another method to make it work:
Basically, create an android library (sharedTestCode), depend on it in your app via testImplementation and androidTestImplementation. In the sharedTestCode build.gradle file, depend on the app. You should now be able to create shared test data and reference them in both types of tests.
Here is a sample project with this setup working:
https://drive.google.com/file/d/1I2CZhTxHGRgCN9UCEjIuWUfFnGxTF_Cv/view?usp=sharing
Second edit: Make sure that any module that depends on the :app project also defines productFlavors and flavorDimensions, matching the
build.gradle configuration of the app’s build.gradle file.
So for example, I had to add this code to my sharedTestModule’s build.gradle file:
flavorDimensions "environment"
productFlavors {
local {
dimension "environment"
}
gae {
dimension "environment"
}
}
Previous response:
I created a support thread:
https://issuetracker.google.com/issues/232420188
and here is the answer from Google about this old way of referencing test data:
Sharing code in this way is not longer supported in the IDE. The
reason this was working before is that in pre-chipmunk we ran Android
studio import with the intellij options set to create a single module
per Gradle project. This option has been removed from IDEA for a good
number of years. Importing this way comes with a lot of issues due to
the fact that intellij modules can only be set up with two scopes for
dependencies and other information, these are compile and test. By
default Android modules effectively have three different scopes (which
roughly correspond to Gradle source sets per variant) main, unitTest
and androidTest. The mapping of these to intellij modules with this
option require us to merge the dependencies of unitTest and
androidTest. Also any custom source set’s need to be merged as well.
This caused a lot of incorrect symbol resolution within the editors
along with a host of other issues.In chipmunk we switch to creating a module per (roughly) Gradle source
set. This allows us to map the information correctly but unfortunately
does result in sharing information between source sets such as this
becoming unsupported by the IDE.To summarize, in order to be correct each source file must only be
present in one module otherwise the IDE has no way of knowing which
context to use. This can also sometimes result in subtle issues with
build. To share sources between test modules you should be able to use
put the code in a separate project and consume it as a dependency with
both testImplementation and androidTestImplementation.