Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Experimental JUnit support in Android + Kotlin not working

Google recently released experimental support for running junit on local JVM in Android Studio. I wanted to try it out and since I am developing my Android app using Kotlin I want my tests classes be written in Kotlin too.

Unfortunately, I can't make it working. I have updated my 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 recognise test folder.

This is my simple test class just 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'

like image 509
Damian Petla Avatar asked Sep 28 '22 16:09

Damian Petla


1 Answers

Unfortunatly, kotlin-gradle plugin doesn't support Junit tests for Android at this moment.

EDIT: Junit support for android was added in Kotlin M12

like image 112
Natalia Selezneva Avatar answered Oct 20 '22 09:10

Natalia Selezneva