KMP: I want the Unit Tests in one module to depend...
# multiplatform
d
KMP: I want the Unit Tests in one module to depend on the Test classes from another module. Anyone successfully doing this in a Kotlin Multiplatform project? This is a fairly well trodden question in Gradle generally [1][2]; but these solutions don't apply to multi-platform Kotlin. I saw this issue which suggests Multiplatform is not capable of establishing a test-to-test dependency at the moment. This is disappointing: I have a module structure that enforces clean architecture in my project, but am having to flatten all Test classes to the 'top level' module because they can't participate in the dependency hierarchy. Any suggestions?
a
I am going to assume you have a structure like this
Copy code
| -- root
  | -- projectA
     | -- src
        | -- commonMain
        | -- commonTest
     | -- build.gradle.kts
  | -- projectB
     | -- src
        | -- commonMain (depends on projectA/commonMain)
        | -- commonTest (depends on projectA/commonTest)
     | -- build.gradle.kts
To mitigate this, I usually endup creating further submodules (yes for test sources) like this
Copy code
| -- root
  | -- projectA
     | -- core
        | -- src
           | -- commonMain
        | -- build.gradle.kts
     | -- test (depends on projectA:core)
        | -- src
           | -- commonMain (shared test sources go here)
           | -- commonTest
        | -- build.gradle.kts
  | -- projectB
     | -- src
        | -- commonMain (depends on projectA:core)
        | -- commonTest (depends on projectA:test)
     | -- build.gradle.kts
I hope that is not too confusing
g
Same approach here (also I don't find it very practical, mainly because it's super verbose if you want to provide some test helpers for each module you have...).