In the JUnit /test I have a test that enumerates classes from /main, looking for specific ones. It worked on Gradle 5.x, but on 6.7.1 ClassLoader.getResources(“my/package”) no longer includes the classes from /main. If I put some of the classes from /main to /test they are getting found. Aside from this, when I run the test in Android Studio ClassLoader.getResources(“my/package”) lists the classes from /main without problems. As Studio uses Gradle, I suspect there might be some new setting, to make the classes from /main visible to ClassLoader run in unit test, from /test folder?
The code is as follows:
@Test
fun checkHashCollisions() {
val classLoader = Thread.currentThread().contextClassLoader!!
val path = packageName.replace('.', '/')
val resources: Enumeration<URL> = classLoader.getResources(path)
assert(resources.hasMoreElements())
}
Stackoverflow post with this issue: Android: after Gradle update to 6.7.1 ClassLoader in JUnit test no longer lists all resources - Stack Overflow
Please advice, how can I make the classes from /main to be returned from ClassLoader.getResources() in a /test.