Similar question: Sharing code between Android Instrumentation Tests and Unit Tests in Android Studio
My setup is the following:
src/test
folder that contains unit tests. These can be either Java or Kotlin classessrc/androidTest
that contains instrumentation tests. These can also be either Java or Kotlin classessrc/sharedTest
is a folder that contains a bunch of utils that are shared between unit and instrumentation tests.
This sharing is defined in gradle as:
sourceSets {
test.java.srcDirs += 'src/sharedTest/java'
androidTest.java.srcDirs += 'src/sharedTest/java'
}
This allows any Java class in src/test
or src/androidTest
to access the utils. but not the Kotlin unit tests. My assumption is that they are not added to the sourceSets.
My question is: how can I add them? I tried:
sourceSets {
test.kotlin.srcDirs += 'src/sharedTest/java'
}
But that doesn't seem to work.