I'm currently converting a pretty simple kotlin jv...
# multiplatform
c
I'm currently converting a pretty simple kotlin jvm library (with unit tests) to kotlin multiplatform. Converting it to multiplatform was easy. But not sure how to move my tests over since im using junit. Is the idea that I just write my test in a bunch of different test directories so that it get executed on each platform. Or do i just write them in a common test directory and then I can execute that on multiple platforms (mostly care about jvm [android] and native [ios] for right now, but want to have this working on wasm as well)
e
./gradlew jvmTest
will run tests in the
jvmTest
source set, which includes
commonTest
, and similarly for other platforms.
./gradlew allTests
will run all the test tasks for all the platforms, which will result in tests in the
commonTest
source set being re-run on every platform
I'll put things in
commonTest
when it's reasonably easy but IMO it's fine to have some tests on only JVM too. if the code under test is really platform-independent, then even testing on one platform should give reasonable coverage.
❤️ 1
j
add kotlin-test dependency, replace
org.junit
with
kotlin.test
. you're now 99% done commonizing the tests (probably)
👀 1
☝️ 2
👌 1
e
biggest things I hit when doing that are assert messages are different and there's no parameterized tests, but for the simple things yes
c
Basically what other replies mentioned is that you should put cross platform tests in commonTest to be executed on each platform. However current limitations of the KMP testing framework may make it impractical. Alternative (less ideal) would be to test common code on one specific platform completely, and write only small subset of tests on other platforms to cover some conner cases (for example all expect/actual cases).