https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
c

CLOVIS

09/06/2023, 2:49 PM
Hi! Do you know if there is a way to programatically declare test cases with Kotlin/Native? For example, to create a
for
loop that creates multiple tests. I've done that before for Kotlin/JVM by declaring a JUnit5
@TestFactory
, and with Kotlin/JS by using dynamic to access the test list, but I have no idea how to do that with Kotlin/Native.
👀 1
m

mbonnin

09/06/2023, 2:57 PM
+1 not exactly the same but having parameterized KMP tests would be handy
k

kevin.cianfarini

09/06/2023, 3:08 PM
I do a poor-mans parameterized test.
Copy code
@Test fun theTest() { 
  (0..10).forEach { i ->
    parameterized(i)
  }
}

private fun parameterized(i: Int) {
  assertEquals(...)
}
c

CLOVIS

09/06/2023, 3:10 PM
@kevin.cianfarini I thought about this, but I'm going to use it to declare all tests…
m

mbonnin

09/06/2023, 3:11 PM
@kevin.cianfarini works but loses some cool features like actually see the failing test in the report and most importantly running only one test with
--tests
c

CLOVIS

09/06/2023, 3:14 PM
plus1 1
m

mbonnin

09/06/2023, 3:14 PM
Ha I was going to suggest this 😄
c

CLOVIS

09/06/2023, 3:15 PM
I have an in-house test framework that uses this for JVM and JS, I'm trying to make it into a standalone library with support for all platforms, but it will probably require hitting some Kotlin/Native internals and I don't know them
Also, welcome back to this topic @Adam S 🙂 I'd greatly appreciate some magic like you found last time 😇
a

Adam S

09/06/2023, 3:17 PM
I would try taking a look through the Kotest sources
haha I'd like to find some magic too
c

CLOVIS

09/06/2023, 3:20 PM
I'm a bit wary of looking through Kotest sources. Last time I tried to use them, Kotest just wasn't able to run JS tests (that's why I started making my own lib in the first place).
I guess it was probably fixed since? But well
a

Adam S

09/06/2023, 3:20 PM
yeah, Kotest had issues with nested Kotlin/JS tests, and probably still does, but the Native tests work fine
e

Edoardo Luppi

09/06/2023, 7:13 PM
Yes Kotest still doesn't work correctly with JS in some cases, and it doesn't report failures correctly, that's why I'm not using it yet
Plus let's be honest, the fact you can't run common tests from the gutter is THE blocker IMO. Too handy