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

Rob Murdock

04/17/2020, 3:24 PM
top of the brain thought with no research so far: does the multiplatform kotlin-test package only support annotation based test loading? It’d be nice to be able to register a test function on-the-fly (which would allow for Mocha-like test frameworks to be written).
k

kpgalligan

04/17/2020, 5:07 PM
For native, the compiler actually generates the test code, so currently as-designed, that would be difficult (but maybe that could be changed?). I don’t think there would be any hot-loading of code, and there’s minimal reflection, which would make this kind of stuff difficult currently.
r

Rob Murdock

04/17/2020, 6:04 PM
I wouldn’t want persay hot-loading (I’m totally fine having everything compiled a single buildtime), and if it would require reflection that suggests there’s something weird about the underlying test runners. That said, maybe some of the platform test runners wouldn’t support adding / removing tests at runtime, and that’d be the killer. Which is too bad, because there’s nothing about a test runner in principle that should stop this, and given Kotlin’s lamda syntax one could make it real pretty.
k

kpgalligan

04/17/2020, 6:05 PM
I don’t think you’d be able to dynamically call the annotated methods, in native at least. You could structure your tests another way, but annotated test methods wouldn’t work (again, as is)
r

Rob Murdock

04/17/2020, 6:07 PM
Annotation processing should boil down to collecting the function references into a list and iterating through them (or however your test runner chooses to run them). What I’m talking about is basically skipping the extra annotation processing step and adding to that list directly (possibly using both methods of test collection).
k

kpgalligan

04/17/2020, 6:10 PM
OK, so you’re saying you can just pass a lambda, assuming it conformed to the protocol (which would presumably be no-arg)? Yeah, although for native it would still need to “compile”. What are you thinking WRT on-the-fly?
r

Rob Murdock

04/17/2020, 6:11 PM
Oh, in theory you could do something like, write a loop that registers test functions for a number of scenarios
it makes parameterized testing a trivial programming exercise
k

kpgalligan

04/17/2020, 6:11 PM
I was just going to say “parameterized”. It’s a big deal missing feature for some folks
r

Rob Murdock

04/17/2020, 6:12 PM
Yeah, its one of the drawbacks of using meta-programming with annotations instead of just… programming
2 Views