Good afternoon, quick question, I’m implementing s...
# multiplatform
a
Good afternoon, quick question, I’m implementing some tests on my kmm project and wanted to save the json payloads on separate files, is there a way to load those? from the jvm test env?
j
These aren't common tests? Just JVM tests?
a
They are the common but run on jvm
j
What other targets are you supporting? Are you only running the common tests on the JVM and not the other targets?
I'd recommend putting the tests in jvmTest if you only intend to run them with the jvm target. If they're testing common code, it's good to have them run on all supported platform targets.
There is no common API for loading resources, but you can create expect/actual implementations with a common interface. Besides the common runtime API, you also need to ensure the resources are included in the runtime .jar or in the binary's current directory or other app bundle. How to do this varies slightly depending on the platform target.
I've found some targets handle embedding resources in their own resources directory by default, others need some gradle Copy task configuration to work. JVM likely works (I know Android does). Native doesn't, however. None of them seem to support copying resources from the common source set though, without explicitly configuring this directory as a resources source.
a
This is just for testing purposes and i have the library built independently from the app that consumes it
Since all the logic resides in the common with a small list of adaptations for iOS, there's no point in implementing an entire project to run the tests
j
If you include the json files in the jvmTest/resources folder, they should be available to load from the .jar at runtime with something like
javaClass.getResource("path/to/resource.json").readText()
.
a
Thanks!