Koltlin 1.3.61 - Multi platform project - Not able to run java test in jvmTests

451 views Asked by At

I created a multiplatform project using Intellij2019.3.1. The project contains only default sample classes created by Idea. I am trying to run a java test in kotlin 1.3.61 using IntelliIdea(2019.3.1). When I try to run the jvm test then it's fail with FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jvmTest'.
> No tests found for given includes: [sample.TestJava](filter.includeTestsMatching)

Please see the build.gradle file which was created by Idea by default

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
}
repositories {
    mavenCentral()
}
group 'com.example'
version '0.0.1'

apply plugin: 'maven-publish'

kotlin {
    jvm()
    js {
        browser {
        }
        nodejs {
        }
    }
    // For ARM, should be changed to iosArm32 or iosArm64
    // For Linux, should be changed to e.g. linuxX64
    // For MacOS, should be changed to e.g. macosX64
    // For Windows, should be changed to e.g. mingwX64
    macosX64("macos")
    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 kotlin("org.junit.jupiter:junit-jupiter-api:5.3.2")
                //implementation kotlin("org.junit.jupiter:junit-jupiter-engine:5.3.2")

            }
        }
        jsMain {
            dependencies {
                implementation kotlin('stdlib-js')
            }
        }
        jsTest {
            dependencies {
                implementation kotlin('test-js')
            }
        }
        macosMain {
        }
        macosTest {
        }
    }
}

Could someone please help

2

There are 2 answers

1
greyhairredbear On

Not sure if this is the solution to your concrete problem, but whenever IDEA gave me an error like this "no tests found" message you got, it was because my project (with the soirces I wanted to test) failed to compile.

Oddly enough, IDEA didn't give me a warning that it hit a compiler error somewhere along the way... So I'd advise you to check your code compiles fine all the way.

As I said, maybe this isn't the solution to your specific problem, just an educated guess. To be sure about it, one would need some code to reproduce the error.

0
nantitv On

Solution has been provided in https://discuss.kotlinlang.org/t/koltlin-1-3-61-multi-platform-project-default-idea-project-not-able-to-run-java-test-in-jvmtests/15962/3

Quoting from kotlin forum

By default, Java sources are not supported in MPP project. You have to add the support explicitly using withJava() DSL: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#java-support-in-jvm-targets 1. Please try it.