Hey there! I know we can run Kotlin Multiplatform ...
# multiplatform
m
Hey there! I know we can run Kotlin Multiplatform tests on iOS simulators. Can we also run them on real iOS devices? I’d really love to test some Bluetooth-related code in an automated fashion!
😬 1
j
You can perfectly run your Kotlin code on real iOS devices, that’s the goal actually. 😄
m
Yes, I know that - the question is if this works from unit tests ;)
j
Sorry, I missed that important part, and I don’t know the answer to that. 😅
v
./gradlew iosSimulatorArm64Test
is what I'm doing although its not perfect. Does not work with CC / sqldelight
m
Yeah, that all runs on a simulator. I’m looking for how to run these on a real device 🙂
j
Tests are just normal binaries that you can run anywhere
m
Well - I'll see if I can get it working with Kotlin multiplatform / Native. I didn't find any resource how to do that yet
j
Once I get to a computer I can try to look
m
Oh, you might be right! I can call
./gradlew linkDebugTestIosArm64
, and it actually compiles a
test.kexe
binary:
Copy code
$ file build/bin/iosArm64/debugTest/test.kexe
build/bin/iosArm64/debugTest/test.kexe: Mach-O 64-bit executable arm64
Now I just need to find out how to run that using
xcrun
or
xcodebuild
d
I think your best bet is going directly through Xcode via the
iosApp
. Write a test in the iOS application that exercises the shared library code, and launch via Xcode targeting a connected device. The
shared
library only supports running iOS tests via
simctl
- https://github.com/JetBrains/kotlin/blob/8c2b2eb27816dcae23f284c02bd446a139f06a2c/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTest.kt#L256 - which is not capable of launching on a connected device. Conceptually, the
shared
tests are unit tests in a KMM project. Neither the Android nor iOS targets are configured to run on real devices. The Android tests run on the JVM, and the iOS tests run on the simulator. To run Android tests on a device, there is
androidAndroidTest
, but AFAIK there is no ready iOS equivalent. See https://touchlab.co/understanding-and-configuring-your-kmm-test-suite/ for further details. If you do manage to figure out how to run the shared test binary on a non-jailbroken device, I'd be curious what the command was. I've been toying locally, but can't get
xcodebuild
to create an archive of the test binary that I can sign/install on my device:
Copy code
xcodebuild -exportArchive -archivePath ./shared/build/bin/iosArm64/debugTest -exportOptionsPlist ./shared/build/bin/iosArm64/debugTest/test.kexe.dSYM/Contents/Info.plist
error: archive at path '/Users/darron/Development/example-kmm/shared/build/bin/iosArm64/debugTest' is malformed
309 Views