moko-resources
moko-resources copied to clipboard
commonTest resources support
Need support to add resources in commonTest directory and use in tests
maybe help - https://gist.github.com/dellisd/a1df42787d42b41cd3ce16f573984674
maybe help - https://kotlinlang.slack.com/archives/C3PQML5NU/p1620210487397100?thread_ts=1620041749.316000&cid=C3PQML5NU
Ok, I finally managed to do it, although there are some cases that still don't work... I put the shared test resources under commonTest/resources, and then add the following snippet in the shared project's build.gradle.kts: afterEvaluate { listOf("debug", "release").forEach { variant -> val copyTaskName = "copyResources${variant.capitalize()}UnitTest" tasks.register<Copy>(copyTaskName) { from("$projectDir/src/commonTest/resources") into("$buildDir/tmp/kotlin-classes/${variant}UnitTest/") } tasks.getByName("test${variant.capitalize()}UnitTest") { dependsOn(copyTaskName) } } tasks.register<Copy>("copyResourcesIosX64DebugTest") { from("$projectDir/src/commonTest/resources") into("$buildDir/bin/iosX64/debugTest/") } tasks.getByName("iosX64Test") { dependsOn("copyResourcesIosX64DebugTest") } } and then I have a expect/actual class to load resources: expect class TestResource(path: String) { val content: String? } actual class TestResource actual constructor(path: String) { actual val content: String? = NSString.stringWithContentsOfFile(NSBundle.mainBundle.pathForResource(path, null)!!) as String? } actual class TestResource actual constructor(path: String) { actual val content: String? = this::class.java.classLoader?.getResource(path)?.readText() } Be careful! The into directories seem to change depending on the Android Studio / Gradle version
Upvote for this one ! :-) I'm noob in gradle unfortunately. xD
I wonder what the resources-test artifact does. I guess it is not support of test resources in commonTest?
resources-test artifact contains createMock***Resource functions. to create in tests mocks of ImageResource, StringResource and others.
current issue about generation resources from commonTest/resources
in #575 added support of resources in any sourceset (including tests), but this case should be tested before close of issue