I have setup a kotlin multiplatform project and want to run junit tests.
But a
gradle clean build
just delivers:
Kotlin Multiplatform Projects are an experimental feature.
BUILD SUCCESSFUL in 1s
9 actionable tasks: 9 executed
this is my build.gradle:
buildscript {
ext.kotlin_version = '1.4.0-rc'
}
plugins {
id 'org.jetbrains.kotlin.multiplatform' version "$kotlin_version"
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
kotlin {
jvm {
withJava()
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
implementation kotlin('stdlib-jdk8')
}
}
jvmTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.junit.jupiter:junit-jupiter-engine:5.5.2"
implementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
implementation "org.junit.jupiter:junit-jupiter-params:5.5.2"
}
}
}
}
and this is my test (lies in src/jvmTest/kotlin):
import org.junit.jupiter.api.Test
class JvmTest {
@Test
fun testX() {
println("Hello World")
println("Hello World")
println("Hello World")
println("Hello World")
println("Hello World")
}
}
I would expect the outputs of Hello World, but as you can see, there is no output.
What do I have to change, that the test is executed? Or is it executed and the output is just not shown? What can I do, to see the output of the test?
I've also tried kotlin version 1.3.72. Same result.
EDIT: I changed the test to
import junit.framework.TestCase.assertTrue
import org.junit.jupiter.api.Test
class JvmTest {
@Test
fun testX() {
assertTrue(false)
}
}
Same result, build runs succeful, no test is executed. There are no files in build/reports/tests
adding
tasks.jvmTest{
useJUnitPlatform()
}
in the build.gradle fixes the problem.
build.gradle now looks as follows:
buildscript {
ext.kotlin_version = '1.4.0-rc'
}
plugins {
id 'org.jetbrains.kotlin.multiplatform' version "$kotlin_version"
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
kotlin {
jvm {
withJava()
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
implementation kotlin('stdlib-common')
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
implementation kotlin('stdlib-jdk8')
}
}
jvmTest {
dependencies {
dependsOn commonTest
implementation kotlin('test')
implementation kotlin('test-junit')
implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
runtimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
implementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
implementation "org.junit.jupiter:junit-jupiter-params:5.5.2"
}
}
}
}
tasks.jvmTest{
useJUnitPlatform()
}