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

rsetkus

10/15/2020, 4:15 PM
Hi. I am fairly new to Multiplatform. Sounds quite trivial question but is it possible to run unit tests from IDE for common module? Created an empty project and when clicking 'Run' button 'Nothing here' pops up.
s

streetsofboston

10/15/2020, 4:22 PM
Run the ones from androidMain. This will run the commonMain ones as well.
r

rsetkus

10/15/2020, 4:27 PM
Sorry, but not quite following you. What if the class I want to test is only in commonMain?
g

Giorgos Neokleous

10/15/2020, 4:40 PM
You will have to run it on a target, whether that is android, ios or js. Basically a test for a common-only class needs to run on a specific target
☝️ 1
r

rsetkus

10/15/2020, 5:04 PM
Hmm... that doesn't sound as unit testing. More like integration testing. 🤔 Oh well. Thanks @streetsofboston and @Giorgos Neokleous for clearing this out.
s

streetsofboston

10/15/2020, 5:06 PM
Tests in
commonMain
can never run as-is, because there is no context in which to run them. They must always be run in a target’s context, like androidMain (on a jvm) or iosMain (native), etc. When running your androidMain unit-tests, for example, will run those and the ones in commonMain as well. Same thing holds for the other targets, like iosMain, etc.
☝️ 3
m

mike.holler

10/15/2020, 5:39 PM
"common kotlin" is definitionally not attached to a single runtime. You can have a common test, but when you click the little run arrow ▶️ next to the test function signature you'll see a dropdown with options (js, jvm, etc) for whatever is configured in
build.gradle[.kts]
. You have to have at least one runtime configured to run tests.
./gradlew check
will run on all configured runtimes.
As far as I've seen, there's no way to do that in the IDE.
r

rsetkus

10/15/2020, 7:32 PM
@mike.holler so you want to say that I should see options of defined targets in build script on ▶️ click?
m

mike.holler

10/15/2020, 7:33 PM
@rsetkus hopefully that helps
r

rsetkus

10/15/2020, 7:35 PM
I don't see any options. Is there anything special in the build script to enable IDE support?
Checked plain empty IntelliJ KMM library project. No options as well.
Seems IntelliJ version specific issue. Downloaded latest Community edition and works like a charm.
2 Views