Kotlin Unit Test, Android Studio 1.1 [Resolved - Not supported]



I’m starting an Android project and I’ve setup Kotin (0.10.770).

I have a sourceset for Kotlin:

sourceSets {
  main.java.srcDirs += ‘src/main/kotlin’
  test.java.srcDirs += ‘src/test/kotlin’

I also have it included as a dependency for testComplile:

testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

When I try to run a test though I get class not found, is this something we expect to work with the AS “Experimental” support of unit tests?



What happens if you add the dependency as compile, not testCompile?


I have it in there for both.

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"


testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"


Do you mean that class from kotlin-stdlib isn't found? Or a kotlin class from 'src/test/kotlin'?

Unfortunatly, kotlin-gradle plugin doesn’t support Junit tests at this moment.


My Unit test written in Kotlin is not found.

The suggestion for now then would be to use the JUnit integration in Android Studio 1.1 to test Kotlin classes?
I assume that would work?



I had this same issue. The problem is that I forgot to add the kotlin plugin to my app’s build.gradle file:

apply plugin: 'kotlin-android'


Did you try to add this dependency for junit with kotlin in testCompile?
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"


There seems to be some confusion on which Gradle plugin is used for Kotlin on the Android side. Unit testing via JUnit works with Kotlin on the JVM side, with the kotlin Gradle plugin. My understanding is that the kotlin-android Gradle plugin is used instead of the kotlin one on the Android side.