How do you guys test your kotlin native code (idea...
# kotlin-native
p
How do you guys test your kotlin native code (ideally multiplatform). Do you just add another target jvm to get junit integration in IDEA, or how is your workflow? I have no idea how to set this up properly to be able to generate test from within IDEA etc.
k
I add unit tests in the KMP test source sets
p
Did you have to load any test framework dependencies, or are you using the bundled testing stuff? And more importantly, does this integrate with IDEA properly? (are you able to Alt+Insert -> generate tests)
k
it uses Kotlin Test
i haven't tried generate tests
p
Yeah my main issue is that Kotlin Test doesn't seem to integrate at all with IDEA. No "run tests for implementation", no "jump between implementation and test", no "generate test for", no nothing 😕
maybe i am just doing something wrong, that's why i'm asking for advice
k
i don't use any of that, so hand't noticed, but definitely not surprised
p
why are you not surprised? i just think i'm missing a piece of the puzzle here on how to get a nice workflow
k
because the general integration of testing flows in the KMP plugin is pretty bare bones
p
damn, i really expected this to work better 😕
can't i have a native and a common package and then use intellij's junit5 integration to test code from the common target?
k
yes
well, i don't know about junit5 specifically
er, hold up, forget that. no, you can't use junit to test native code
native != jvm
p
but common?
k
common != jvm either
you common tests are included in all target-specific test binaries
p
so, idk. does this mean there is no real way to get intellij tests integration in kotlin native projects?
k
the crux of the problem is that it needs to be clarified which test source set the tests belong to, and which test target needs to be run
p
all i know is that i want intellij tests integration for any kind of tests for the kotlin native code (or a subset put into common, i really don't care). just some sort of integration
really hoped someone here had played around with this before and had some insights for me
t
Use android studio and the KMM plugin, the KMM template adds test you can run from the IDE.
p
@Tijl when you are in a class and hit
Alt+Insert
and select
Test
can you actually generate a test with the dialog that opens up? I even installed the KotlinTest plugin to support generating those, but whenever i hit the
OK
button, it does nothing and stays open.
t
I would care more about being able to run kotlin-native tests, and to debug them, than to autogenerate a template. I installed the kotlintest plugin, which is a plugin for
kotest
, not the kotlin test annotations that come with kotlin multiplatform. however kotest claims to be multiplatform, and it was able to generate this code in the
androidTest
package:
Copy code
package com.splendo.kaluga.starter.shared

import io.kotlintest.specs.StringSpec
import io.kotlintest.shouldBe

class GreetingTest : StringSpec() {

    init {
        "greeting" { }
    }

}
The fact that it puts in in the android module means the plugin is JVM focused. So that plugin will need to be updated for a seemless experience
p
i can run the kotlin-native tests. but i am so used to the workflow jetbrains IDE's bring, that i really want this to work. but right now, the "OK" button doesn't even do anything (it's not even greyed out) in the generate test dialog
i guess i'm just spoiled... the jetbrain gods giveth, the jetbrains gods taketh