Reputation: 930
I want to test the main function for competitive programming.
Kotlin can have multiple main functions, however how to call specific one?
In other words, how to specify a function in the specific file?
Upvotes: 3
Views: 923
Reputation: 2350
As workaround, In JVM, in tests, we can create Java class which delegates calls to target main
functions.
This is based on the fact that by default FileName.kt
translates into Java class FileNameKt
public final class Mains {
public static void section01() {
Section01Kt.main();
}
public static void section02() {
Section02Kt.main();
}
}
Then use wrapper method in tests:
@Test
fun testMain() {
Mains.section01() // instead of main()
}
Upvotes: 0
Reputation: 3689
It depends on compilation and execution tools:
Upvotes: 2