Kotlin-allopen for android

Yes you can. Because it's a compiler plugin, you'll get all-open code after compilation. So it should work with tests. Don't worry.

Edit: according to the comment area, updating the kotlin plugin version seems work. Currently the newest version is 1.2.41.


First add the dependency in your build.gradle (project) file:

dependencies {
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
    }

After that apply the plugin in your build.gradle (app mobdule) file:

apply plugin: 'kotlin-allopen'

Then specify the list of annotations that will make classes open:

allOpen {
    annotation('com.example.myproject.OpenForTesting')
}

And use this annotation for every class which you want to be open

@OpenForTesting

Here is the Kotlin official documentation about All-open: https://kotlinlang.org/docs/reference/compiler-plugins.html

Hope this help