How are test results reported to Gradle by the Kot...
# gradle
c
How are test results reported to Gradle by the Kotlin plugin? I'm looking into implementing a custom test runner for KMP, but there is no documentation whatsoever on the Gradle side for anything that doesn't use JUnit5. How does the Kotlin plugin do it?
v
What do you think the Kotlin plugin needs to do there?
Afaik there is no way to extend the list of supported test frameworks in Gradle. But as JUnit 5 is specifically designed to support multiple custom test engines, you should be able to achieve what you want through implenting such an engine. Spock 2.x e. g. is also nothing else than a custom JUnit 5 Platform engine.
c
What do you think the Kotlin plugin needs to do there?
Discover the test classes, instantiate test classes, discover the list of tests so filters can work, report execution results to Gradle so they appear in test reports and in IDEA,...
But as JUnit 5 is specifically designed to support multiple custom test engines, you should be able to achieve what you want through implenting such an engine.
To my knowledge, I can't use JUnit5 in K/JS, K/N nor K/WASM.
v
Why not? In the worst case the JUnit engine is just a thin wrapper, calling some other tool that executes the actual tests and then translates the results of that tool back to the JUnit Platform infrastructure. A JUnit engine is totally free in how the test are defined / discovered / executed. It could also just read some database state and report that as tests, or show a GUI so a user can enter the results that should be forwarded, or whatever else you can imagine.
c
JUnit is written in Java, no? How can I get it to execute in the browser or in node? Or on iOS?
Also, the Gradle Test class clearly starts a JVM. It can't run anything else
v
Gradle is written in Java. How do you get it to execute something in the browser or in node or on iOS?
1
Same for the tests
Yes, the engine itself needs to be written in Java, but that does not mean that it cannot invoke other things by any means as I described above
e
Kotlin Gradle Plugin doesn't do anything special for JVM tests
for js/native, KGP pokes at some Gradle internals, which has broken across Gradle releases
v
It should really just provide a JUnit platform engine instead then, then it is also instantly compatible with anything supporting JUnit 5 🙂
c
Yes, the engine itself needs to be written in Java, but that does not mean that it cannot invoke other things by any means as I described above
So that would mean having Gradle start a custom test executor written on the JVM, that exposes a JUnit5 engine, and have that execute the actual test binaries through ProcessBuilder? 🤔
👀 1
It would probably require a compiler plugin on the JS and Native side to generate a main method that instantiates all tests entrypoints 🤔
but then, we can create our own communication protocol between JUnit5 and the JS and Native binaries
👌 1
e
Kotlin compiler already handles native and js tests specially
c
Yes, but it's all internal stuff that we can't access
(btw all of this is because I want to declare tests programmatically, not through their JUnit imitation)
e
at least for native, the resulting binary can be queried for tests and directed to execute specific ones
c
We can't declare tests or test suites ourselves, though
(at least, not that I've been able to find out)