What's the idiomatic way nowadays to configure tes...
# test
m
What's the idiomatic way nowadays to configure test fixtures for common code in a KMP project? Is it easiest to just throw them into a test-specific module and add that as a test-only dependency? Anyone have an example repo they could point me to? I'm trying to add tests for a common src network parser and store some sample HTTP response JSON files as fixtures.
👀 1
✅ 1
o
(I'm always having trouble with the name, as it clashes with the long established JUnit term of fixture as a state holder.) That said, yes: Creating a module with what I'd call test utilities in
commonMain
and adding this module as a test dependency where appropriate is the idomatic way. While not a multiplatform example, this project exhibits the pattern. Other alternatives exist, but these are platform-specific, like the Gradle JVM Test Suite plugin and the
com.android.test
plugin.
e
As for me, modules are already tighten to a build tool and KMP just makes gradle the only one. So I would go to specific solution already.
m
Oliver thanks for the links! I think that approach makes perfect sense for shared code and utils and what not. I'm specifically trying to figure out how to model shared test resources like a JSON file and wondering what the best solution for that is. I was surprised I couldn't find something first-party to support this with the KMP gradle plugin already (I'm imagining something like how Android's resources work, or JVM module's resources). Am I missing something obvious?'
o
There is no first-party solution for resources in KMP (there is compose-multiplatform-resources though). But maybe moko-resources or kotlinx-resources could fit your bill?
m
kotlinx-resources looks like exactly what I need - thanks! I'll give it a go
👍 1