# Multiplatform: Running kotlin.test Common tests and io.kotlintest JVM tests

**URL:** <https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259>\
**Category:** Multiplatform\
**Created:** [December 3, 2019, 9:19am UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259 "2019-12-03T09:19:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/nanodeath/32/1803_2.png) [@nanodeath](https://discuss.kotlinlang.org/u/nanodeath)\
**Post date:** [December 3, 2019, 9:19am UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259/1 "2019-12-03T09:19:10Z")

</div>

I have some tests in my commonTest directory that use the built-in kotlin.test library, and some other tests in jvmTest that use io.kotlintest. I start out with a fairly vanilla build.gradle file.

If I run the `jvmTest` task, it executes my commonTest tests but _not_ my jvmTest tests.

If I go back and add `jvmTest.useJUnitPlatform()` to my build.gradle, then run `jvmTest` again, it executes my jvmTest tests, but _not_ my commonTest tests.

Basically it looks like there’s no way to configure build.gradle such that my commonTest and jvmTests run in the same execution.

Thoughts?

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [December 3, 2019, 10:36am UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259/2 "2019-12-03T10:36:23Z")

</div>

To make it work you need to make the `jvmTest` sourceSet depend on the `commonTest` sourceSet. In addition you will need to add the junit implementation to the dependencies for `jvmTest` (the same is true for any other platform you may want to run the common tests on). Some example of how I’ve implemented it is here:

> <https://github.com/pdvrieze/xmlutil/blob/9c67201298c61c209e818c5b3eca0eb5b5ecb3fc/serialization/build.gradle.kts#L172-L191>

---

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/nanodeath/32/1803_2.png) [@nanodeath](https://discuss.kotlinlang.org/u/nanodeath)\
**Post date:** [December 3, 2019, 7:20pm UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259/3 "2019-12-03T19:20:37Z")

</div>

Thanks…I tried adding `dependsOn commonTest` to my `jvmTest.dependencies` block, but unfortunately this seemed not to work for me. The junit implementation was already present in `jvmTest`:

```groovy
jvmTest {
    dependencies {
        dependsOn commonTest
        implementation kotlin('test')
        implementation kotlin('test-junit5')
        implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
    }
}

```

---

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/nanodeath/32/1803_2.png) [@nanodeath](https://discuss.kotlinlang.org/u/nanodeath)\
**Post date:** [December 4, 2019, 1:11am UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259/4 "2019-12-04T01:11:06Z")

</div>

Alright, this works for me:

```groovy
jvmTest {
    dependencies {
        implementation kotlin('test')
        implementation kotlin('test-junit5')
        implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
        runtimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
    }
}

```

Seems it wasn’t working because there was no (junit) TestEngine to pick up the commonTest-style tests. Not sure how that was ever working, even before kotlintest. Anyway, this works 🙂

---

<div class="post-metadata">

**Author:** ![vk](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vk](https://discuss.kotlinlang.org/u/vk)\
**Post date:** [June 17, 2020, 1:02pm UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259/5 "2020-06-17T13:02:04Z")

</div>

I have similar problems with running tests in multiplatform project. Documentation is very poor I cannot figure out where is the problem ☹ – Would appreciate any help.

I made a test project for illustration (attached)

[KotlinMultiplatformTestProblems.zip](https://discuss.kotlinlang.org/uploads/short-url/f0RqHBgoiodpgfMaSKm4KEtOosa.zip) (57.0 KB)

Here are the main pieces:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/d/d534d1e707867c3d78035915b8a628a6c78462a9.png)

## **build.gradle for ModuleA:**

plugins {  
id ‘org.jetbrains.kotlin.multiplatform’  
}

kotlin {  
jvm{  
}.compilations.all {  
kotlinOptions.noReflect = false  
kotlinOptions.noStdlib = false  
}

```
sourceSets {
    commonMain {
        dependencies {
            implementation kotlin('stdlib')
            implementation kotlin('stdlib-common')
        }
    }
    commonTest {
        dependsOn commonMain
        dependencies {
            implementation kotlin('test-common')
            implementation kotlin('test-annotations-common')
        }
    }
    jvmMain {
        dependencies {
            implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
        }
    }

    jvmTest {
        dependsOn commonTest
        dependencies {
            implementation kotlin('test')
            implementation kotlin('test-junit5')
            implementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
            runtimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
        }
    }
}

```

This is what I am getting:

* * *

Testing started at 14:44 …

> Configure project :  
> Kotlin Multiplatform Projects are an experimental feature.

The Kotlin source set commonTest was configured but not added to any Kotlin compilation. You can add a source set to a target’s compilation by connecting it with the compilation’s default source set using ‘dependsOn’.  
See [https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets)

> Task :ModuleA:cleanJvmTest  
> Task :ModuleA:compileKotlinJvm UP-TO-DATE  
> Task :ModuleA:jvmProcessResources NO-SOURCE  
> Task :ModuleA:jvmMainClasses UP-TO-DATE  
> Task :ModuleA:compileTestKotlinJvm UP-TO-DATE  
> Task :ModuleA:jvmTestProcessResources NO-SOURCE  
> Task :ModuleA:jvmTestClasses UP-TO-DATE

> Task :ModuleA:jvmTest FAILED

FAILURE: Build failed with an exception.

- What went wrong:  
Execution failed for task ‘:ModuleA:jvmTest’.

> **No tests found for given includes: [module\_a.SomeClassTest.testSomeFun]**(filter.includeTestsMatching)

- Try:  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

- Get more help at [https://help.gradle.org](https://help.gradle.org)

## BUILD FAILED in 327ms 4 actionable tasks: 2 executed, 2 up-to-date

---

<div class="post-metadata">

**Author:** ![vk](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vk](https://discuss.kotlinlang.org/u/vk)\
**Post date:** [June 17, 2020, 9:49pm UTC](https://discuss.kotlinlang.org/t/multiplatform-running-kotlin-test-common-tests-and-io-kotlintest-jvm-tests/15259/6 "2020-06-17T21:49:52Z")

</div>

And again answering my own question: this change in jvmTest piece solved my problem:

```
jvmTest {
            dependencies {
                implementation kotlin('test-junit')
            }
        }

```

(the problem was 5 in ‘test-junit5’)
