Unable to extract commonMain
resources in commonTest
when running android unit tests in KMM app (missing JVM resource generation for androidTest
?).
#393
darronschall
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I'm using moko-mvvm in a KMM app to share common view model business logic between my Android and iOS app. I'm also using moko-resources.
I'm able to use my
commonMain/resources
in my Android and iOS UI code without issue, e.g.:The problem I'm having is that I would like to use a resource string in my viewModel. There is no helper for this out-of-the-box, so I created a platform wrapper, like this:
I can then provide this wrapper to my view model. This lets me go through the
Resources
interface to extract a resource string that the viewModel can bind to.For example, given this resource (in
commonMain/resources/MR/base
):I can use my
Resources
interface to get the value at runtime in my view model:This works great. When running my Android and iOS app, I can see the "Demo error message" string in the view.
The problem I'm having is in my view model test declared in
commonTest
. I'm unable to extract the resources becauseandroidTest
runs on the JVM as unit tests, and it doesn't look like moko-resources generates those resources.I made a
createResources
test helper, so that when running the tests I can use the correct implementation for myResources
wrapper. This type of test passes when runningiosSimulatorArm64Test
(the resources are available and work fine), but fails when runningtestReleaseUnitTest
because the JVM resources cannot be found.Here's what
createResources()
looks like:I tried to have my
androidTest
resource loader take the same kind of approach that moko-resourcesjvmMain
does, but it's still not quite right.I also tried using the
resources-test
library, but thecreateStringResourceMock()
does not help me pull the string value from the strings.xml file in mycommonTest
test.In summary:
How can I instruct moko-resources to generate JVM resources so that I can use them in
androidTest
? I don't want to add a JVM target to my project (it is iOS + Android only). This seems like a bug that can be solved with a plugin update?androidTest
that I can take other than the ones I've already tried?Related, would a future release of moko-resources be open to including the
Resources
interface and platform implementations, to make it easier to use resources in moko-mvvm view models like I demonstrated? I'm happy to submit a PR if others see value in it.Beta Was this translation helpful? Give feedback.
All reactions