byteunits icon indicating copy to clipboard operation
byteunits copied to clipboard

Switch to platform-agnostic kotlin-test coordinates

Open JakeWharton opened this issue 2 years ago • 5 comments

Did this from the web UI. Will it work?

JakeWharton avatar Jan 25 '23 04:01 JakeWharton

Nope, there is no jvm only Test annotation, you need to choose a jvm test framework: https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/-test/

hfhbd avatar Feb 08 '23 21:02 hfhbd

The default is JUnit 4. I've never had to specify. Also... I have no memory of this PR...

JakeWharton avatar Feb 09 '23 01:02 JakeWharton

Yeah, the default test framework used by Gradle is JUnit 4. Gradle needs to start the test framework as well as parsing the results, so you have to specify the framework (or use the default). But the chosen test framework is not passed to the dependency management. So you have to choose a dependency for the jvm.

hfhbd avatar Feb 09 '23 08:02 hfhbd

I've never had to do that except like five years ago before they merged all the multiplatform stuff into single modules. I suspect it's due to being multiplatform with only a single target.

JakeWharton avatar Feb 21 '23 04:02 JakeWharton

Oh, you are right, the module file should resolve it based on the Gradle attributes for the variantjunitRuntimeVariant.

I think, I found the reason, it is not only one single multiplatform target but the combination with withJava. By default, there is no "testImplementation" using multiplatform only, there is a commonTestImplementation. But with withJava this configuration is created, but it is a java configuration only (the kotlin jvm) configuration would be jvmTestImplementation.

But now a kotlin mpp artifact is added to a jvm configuration only and the automatic resolvment of kotlin-test-junit does not work.

plugins {
    java
}
repositories {
    mavenCentral()
}
dependencies {
    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnit() // has no effect
}

hfhbd avatar Feb 21 '23 16:02 hfhbd