Hi. I am fairly new to Multiplatform. Sounds quite...
# multiplatform
r
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
Run the ones from androidMain. This will run the commonMain ones as well.
r
Sorry, but not quite following you. What if the class I want to test is only in commonMain?
g
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
Hmm... that doesn't sound as unit testing. More like integration testing. 🤔 Oh well. Thanks @streetsofboston and @Giorgos Neokleous for clearing this out.
s
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
"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
@mike.holler so you want to say that I should see options of defined targets in build script on ▶️ click?
m
@rsetkus hopefully that helps
r
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.