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

Nick Halase

01/25/2020, 11:00 PM
Can someone please enlighten me on unit testing with Kotlin multiplatform? As I understand it,
commonMain
and
commonTest
SourceSets
exist regardless of the target. If my project only has ios and android targets, does that mean I can't run unit tests on the common code contained in
commonTest/test
?
b

basher

01/25/2020, 11:14 PM
common code is executed for each platform you support. So commonTest will just be run for each platform that you run unit tests
n

Nick Halase

01/25/2020, 11:18 PM
"So commonTest will just be fun for each platform that you run unit tests" can you elaborate on this, please?
b

basher

01/25/2020, 11:18 PM
Whoops typo. Fixed.
When you run tests for iOS, it'll run tests in commonTest + iosTest. When you run android tests, it'll run tests in commonTest and androidTest
n

Nick Halase

01/25/2020, 11:20 PM
So there's no way to just execute the tests that are in commonTest?
b

basher

01/25/2020, 11:21 PM
You could (with some configuring probably), but which platform would you run them on? There's no platform independent artifact. Ultimately, the code has to run on a particular platform
n

Nick Halase

01/25/2020, 11:22 PM
Interesting, I would have thought common has an implicit JVM platform being Kotlin and all
b

basher

01/25/2020, 11:24 PM
Nope. If you want that, you add JVM as a target, and then you run JVM tests
n

Nick Halase

01/25/2020, 11:25 PM
So I should conceptually imagine my common code to have a runtime of some platform rather than generic JVM code that can be compiled to a platform native binary.
👌 1
lol if that makes sense for where the confusion is coming from
b

basher

01/25/2020, 11:25 PM
Common misconception is that common implies some kind of platform-independent artifact or something. It's really more just about it being common to all sources, so it can't uses platform-specific code/libraries and must be compatible with all targets
n

Nick Halase

01/25/2020, 11:26 PM
^ exactly. Yeah, I guess I got bit by that misconception.
Thank you so much for the clarification.
b

basher

01/25/2020, 11:26 PM
No prob 👍
l

lavong

01/26/2020, 9:26 AM
interesting! does that imply, that tests in
commonTest
aren’t supposed to be runnable from AS/IDEA? i was wondering why the
run as test
button is not showing up for my common test
b

basher

01/26/2020, 3:42 PM
They should be runnable, but support varies based on the targets you have setup + bugs: 1. Native targets are newer, and IDEA support is still "up and coming" 2. JVM/android targets should work fine 3. Pretty sure there are new bugs in Kotlin 1.3.60 that broke support for 2. Should be fixed in 1.3.70
l

lavong

01/26/2020, 4:43 PM
thought as much. thx!
👍 1
s

Sam

01/27/2020, 4:02 PM
FWIW, I usually use a JVM target for running tests while I’m developing because they run the fastest. Every once in a while I do a sanity check on the other platforms.
n

Nick Halase

01/27/2020, 5:11 PM
@Sam yeah, that's what I ended up doing. The unit tests I was writing were simple enough and basically sanity checks. I just needed fast feedback.