Not able to run unit tests on kotlin Multiplatform project

Hi all,

I am trying to create a kotlin Multiplatform library which can later convert into java and javascript using IDEA 2019.3, kotlin 1.3 .

I created a simple junit (4) test class and configured it as follows.

package sample;
import org.junit.Test;

public class Tests {
    @Test
    public void test1(){
        System.out.println("here");
    }

}

But while running, it’s failing with

Process finished with exit code 1 Class not found: “sample.DummyTest”

I could not figure out what am I doing wrong. Please advice.

Do your tests run on the CLI through Gradle? If so, read on.

In addition to all the things found in the docs, I discovered that – even for JVM-only projects! – two dependencies are needed for IDEA to run the tests:

dependencies {
    implementation(kotlin("stdlib"))
    compileOnly("org.jetbrains", "annotations", "18.0.0")

    testImplementation(kotlin("test-junit5"))
    testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.5.2")

    // IDEA needs those:
    testCompileOnly("org.junit.jupiter", "junit-jupiter-api", "5.5.2")
    testCompileOnly("org.junit.jupiter", "junit-jupiter-params", "5.5.2")
}

That said, I think I observed no tests being found; your problem seems to be different. If so, my bad.

Thanks for the reply.
I was trying to running it via IDEA itself. Right click on a test → then Run TestName…

Try to delete the created Junit run configuration and create a Gradle one (build and run tests using Gradle in “File | Settings | Build, Execution, Deployment | Build Tools | Gradle”). Does this help?

Thanks for the reply. But it did not help.
I deleted the created Junit run configuration and created a Gradle one.

Then I rightClick on jvm class and pressed run. But it failed with following exception.
Just to note my tests are still annotated with junit.

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':jvmTest'.

> No tests found for given includes: [mypackage.TestSample](filter.includeTestsMatching)

If you have a multi-module MPP project, it’s probably this bug: https://youtrack.jetbrains.com/issue/KT-35038. Please check the generated run configuration, it might be missing the correct Gradle project value as described in the issue. This is only a problem when running tests from gutter, ie. running jvmTest task from the Gradle tool window in IDEA should work fine.

@Alexey.Belkov as far as I understood https://youtrack.jetbrains.com/issue/KT-35038?_ga=2.238248132.510151518.1578909478-1531068909.1578050245 is talking about multi module multi platform project. Mine is single multiplatform project.
In the javaTest, I wrote another Testfile( A.kt)with kotlin.test.Test annotation and that runs.
But java test file (*.java) is not running

Discussion continued in Koltlin 1.3.61 - Multi platform project - Default Idea project - Not able to run java test in jvmTests

My problem was in single path to kotlin and java tests. So kotlin tests are in root/src/test/kotlin/package and they are running fine with gradle :cleanTest :test and java tests must be in root/src/test/java/package. Otherwise neither compileTestKotlin nor compileTestJava will not find java tests to compile.