JUnit experimental support in Android + Kotlin not working

Google recently published experimental support for running junit on a local JVM in Android Studio. I wanted to try, and since I am developing an Android application using Kotlin, I want my test classes to be written in Kotlin.

Unfortunately, I cannot get it to work. I updated the gradle configuration:

sourceSets { main.java.srcDirs += 'src/main/kotlin' androidTest.java.srcDirs += 'src/androidTest/kotlin' test.java.srcDirs += 'src/test/kotlin'//this line was added } testCompile 'junit:junit:4.12' testCompile "org.mockito:mockito-core:1.9.5" 

Android Studio recognizes the test folder.

This is my simple test class to see if it works

 public class MyFirstTestClass { [Test] fun firstTest() { println("I am OK") Assert.assertTrue("".isEmpty()) } } 

If I try to run it, I get the following message

Class not found: 'com.example.MyFirstTestClass'

+5
source share
1 answer

Unfortunately, the kotlingradle plugin does not currently support Junit tests for Android.

EDIT: Junit support for android was added in Kotlin M12

+4
source

Source: https://habr.com/ru/post/1213974/


All Articles