Can anyone link me a good or simple example of a m...
# multiplatform
l
Can anyone link me a good or simple example of a multiplatform project that tests common code with common test sources on Android as an instrumented test?
k
if you had common test sources, you wouldn't be able to reference the android SDK, so what would you gain from running the tests as instrumented?
l
@Kris Wong The code being tested has
actual
symbols that reference Android APIs.
m
wouldn't that require android module/sourceset to be built/available for those tests to run?
k
yes
m
not an expert on this, but sounds like you want to test Android module with common test sourceset included
k
i would think you could create your
androidTest
target with a dependency on
commonTest
, and then adjust your android source sets so that the tests are picked up correctly
l
I have a working multiplatform module that supports macOS, iOS and Android. The tests run fine on macOS (using
macosX64Test
), with the uncompleted ones failing as expected. On Android, I tried to run
connectedDebugAndroidTest
, but it doesn't seem to run anything as no failure is reported for the
TODO()
tests, nor success for the others.
k
did you set android.sourceSets.androidTest.java.srcDirs?
l
@Kris Wong I didn't. Should I put
commonTest
into it?
k
that sets
test
, but same idea
putting commonTest in there may work. if not then adding an
androidTest
and setting a source dependency should.
l
I added that (Gradle Kotlin DSL compatible):
Copy code
sourceSets.getByName("androidTest") {
        java.srcDir("src/commonTest/kotlin")
    }
and now, the tests run! Thank you for the hint! Will probably need to add that for
androidTest/kotlin
too, as you showed, so it works when I write Android specific test code.
👍 3
Wooops, taking back what I said, now it tells me it found no tests…
k
the test runner can certainly be finicky
l
It seems I forgot to set it up, will check again once I can reach my laptop later today.
d
I personally generally use this config for this kind of problems: https://github.com/algolia/instantsearch-android/blob/develop/helper/build.gradle.kts
l
Thank you @dany, it has been helpful reassuring me people got it working, and now I got the setup I want.