Android Studio 3.0 Canary 1 - Kotlin unit tests don't run from command line


#1

This might be a silly question but…

Steps:

Using Android Studio 3.0 Canary 1:

Create new android project with kotlin support.
Change the assertion in ExampleUnitTest to assertEquals(5, (2 + 2).toLong())
From the command line ./gradlew clean test

The build does not fail and the kotlin unit test does not appear to run. It does run (and fail) from inside Android Studio.

The kotlin instrumented test works from the command line, just not the kotlin unit test.

What am I doing wrong, does something else need to be added to the build.gradle or the test class?


#2

https://stackoverflow.com/questions/44079918/android-studio-3-0-canary-1-kotlin-tests-or-java-tests-referring-to-kotlin-clas
it’s answered here, or check out my example repo here: https://github.com/vuhung3990/StarterKit


#3

This following is what is currently needs to be added to app/build.gradle to make it work.

afterEvaluate {
    testReleaseUnitTest.dependsOn copyKotlinReleaseUnitTestClasses
}

task copyKotlinReleaseUnitTestClasses(type: Copy) {
    from "build/tmp/kotlin-classes/releaseUnitTest"
    into "build/intermediates/classes/test/release"
}