https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
l

louiscad

09/09/2019, 9:06 AM
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

Kris Wong

09/09/2019, 9:14 AM
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

louiscad

09/09/2019, 9:22 AM
@Kris Wong The code being tested has
actual
symbols that reference Android APIs.
m

Marko Mitic

09/09/2019, 9:23 AM
wouldn't that require android module/sourceset to be built/available for those tests to run?
k

Kris Wong

09/09/2019, 9:29 AM
yes
m

Marko Mitic

09/09/2019, 9:31 AM
not an expert on this, but sounds like you want to test Android module with common test sourceset included
k

Kris Wong

09/09/2019, 9:32 AM
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

louiscad

09/09/2019, 9:34 AM
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

Kris Wong

09/09/2019, 9:36 AM
did you set android.sourceSets.androidTest.java.srcDirs?
l

louiscad

09/09/2019, 9:42 AM
@Kris Wong I didn't. Should I put
commonTest
into it?
k

Kris Wong

09/09/2019, 9:45 AM
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

louiscad

09/09/2019, 9:50 AM
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

Kris Wong

09/09/2019, 10:04 AM
the test runner can certainly be finicky
l

louiscad

09/09/2019, 10:17 AM
It seems I forgot to set it up, will check again once I can reach my laptop later today.
d

dany

09/09/2019, 11:06 AM
I personally generally use this config for this kind of problems: https://github.com/algolia/instantsearch-android/blob/develop/helper/build.gradle.kts
l

louiscad

09/10/2019, 9:48 AM
Thank you @dany, it has been helpful reassuring me people got it working, and now I got the setup I want.
4 Views