'Kotlin Multiplatform Project Unit Test Issue

Today I just updated my Android Studio to

Android Studio 3.5.2
Build #AI-191.8026.42.35.5977832, built on October 31, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.1

I updated the Android Studio because it prompts error to me when the kotlin version is below 1.3.60.

However I am facing problem with the unit test file. Previously I can run the unit test without any problem. Now, when I click the run button besides the function name (on the left), it shows Nothing Here.

enter image description here

Below is all my dependencies

// build.gradle

buildscript {
ext.kotlin_version = '1.3.60'
repositories {
    google()
    jcenter()
    maven { url "https://kotlin.bintray.com/kotlinx" }
}

dependencies {
    // classpath 'com.android.tools.build:gradle:3.4.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}

allprojects {
  repositories {
    google()
    jcenter()
  }
}

task clean(type: Delete) {
   delete rootProject.buildDir
}


 apply plugin: 'kotlin-multiplatform'
 apply plugin: 'kotlinx-serialization'

kotlin {
targets {
    final def iOSTarget = presets.iosX64 // Simulator

    fromPreset(iOSTarget, 'iOS') {
        binaries {
            framework('SharedCode')
        }
    }
    fromPreset(presets.jvm, 'android')
}

sourceSets {
    commonMain {
        dependencies {
            api 'org.jetbrains.kotlin:kotlin-stdlib-common'
            implementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
            implementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
            implementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
            implementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
        }
    }

    iOSMain {
        dependsOn commonMain
    }

    androidMain.dependencies {
        api 'org.jetbrains.kotlin:kotlin-stdlib'
    }

    commonTest {
        dependsOn commonMain
    }
}
}

Is there something that I missed out in this new Android Studio and kotlin version. I have been struggling with this for hours. Browsed web but seems couldn't find any help.

Thanks



Solution 1:[1]

In my case, this issues happened when I updated from

  • Android Studio 3.5.3 and Kotlin plugin version v1.3.50-release-Studio3.5-1

to

  • Android Studio 3.6.3 with Kotlin plugin 1.3.71-release-Studio3.6-1

All of my common Kotlin MPP tests were not running from the expected IDE side function "green" run and displayed the Nothing here message too.

I tried a few things, one of them being a full uninstall and then install but nothing seemed to work.

What ended up working for me was (with some caveats):

  • created a new test (works with existing tests too, but just as an example)

pic 1

to make sure the Nothing Here shows.

Then:

  • open the dropdown next to the Emulator selected one and click Edit Configurations
  • under Android JUnit click the + button to add a new configuration
  • it should look like this:

pic2

make sure the test kind is Class and that you have the correct path to the file. For example:

com.my.path.is.correct.MyNewTestCase

Also, make sure you have the correct module for the common Kotlin; in my case it was common (not commonTest).

After the above you should be able to run the test class from the main Run button (again, next to the Emulator drop down list) and even run it as Debug.

The "green" run button next to the function will still say Nothing here but adding a breakpoint and running the new configuration from the main Debug button does work for me:

enter image description here

This is obviously not perfect, but it was the only way to have it working from the IDE that I could find.

Hope it helps!

Solution 2:[2]

Clean install Android Studio fixed this issue. Never thought this problem will occurr. Updated Android Studio several times in the past, and this is my first such issue encounter.

Solution 3:[3]

I have tried all the solutions that provided above, NONE worked for me. Finally I kept only plugins that are bundled with Android studio and disabled every other (restart studio) . I started seeing the menu on gutter to run the tests. Once this is fixed, I started enabling those disabled plugins ONE-BY-ONE. If the plugin which cause this issue identified, then decide what to do with it based on your environment and dev requirement.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 alvinWB
Solution 3 mask