https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
p

pajatopmr

03/13/2019, 6:02 PM
How do test resources get moved such that they will be accessible via
classLoader.getResource("foo.txt")
during a test? And is the package relevant?
I see the resources under “…build/processedResources/…” but not in “build/classes/kotlin/jvm/test/…” where I expect them to be.
Does one have to create a Gradle copy task to make that happen with Kotlin MPP?
k

Kris Wong

03/13/2019, 6:09 PM
I did not try any manual gradle copying, but I was not able to make that work. Someone else on here mentioned just using plain old File with a relative path.
p

pajatopmr

03/13/2019, 6:12 PM
That’s a good clue but not quite the final answer. Thanks for the tip.
For those who care, here’s what I did to get to yes: 1) Wrote a Gradle copy task to copy the resource from the source set to the build tree. 2) invoked that task. 3) accessed the file using the
getResource("resource-file-name")
in a test function. 4) Broke out the champagne when it actually worked!
Ping me if more details are desired.
k

Kris Wong

03/13/2019, 8:11 PM
i am curious about that
p

pajatopmr

03/13/2019, 8:59 PM
Here’s the task added to build.gradle.kts: tasks.register<Copy>(“copyResources”) { from(file(“$projectDir/src/jvmTest/resources/application.conf”)) into(file(“$buildDir/classes/kotlin/jvm/test/“)) }
And here’s the test function:
@test fun `find resources`() { val paths = object {}.javaClass.classLoader.getResources(“application.conf”).toList() assertEquals(1, paths.size, “Wrong size.“) }
k

Kris Wong

03/13/2019, 9:03 PM
easy enough
a

Alexey Belkov [JB]

03/14/2019, 8:38 AM
k

Kris Wong

03/14/2019, 1:25 PM
looks like it's the same issue