Hi! Do you know if there is a way to programatical...
# kotlin-native
c
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
+1 not exactly the same but having parameterized KMP tests would be handy
k
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
@kevin.cianfarini I thought about this, but I'm going to use it to declare all tests…
m
@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
@mbonnin please upvote https://youtrack.jetbrains.com/issue/KT-46899 🙂
plus1 1
m
Ha I was going to suggest this 😄
c
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
I would try taking a look through the Kotest sources
haha I'd like to find some magic too
c
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
yeah, Kotest had issues with nested Kotlin/JS tests, and probably still does, but the Native tests work fine
e
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