Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded

后端 未结 8 796
星月不相逢
星月不相逢 2021-01-17 11:30

I try to run Kotlin instrumentation tests for android.

In my app/build.gradle:

    android {
        dataBinding {
            enabled = true
               


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-17 11:45

    For those who still have problems like this, This happens because Kotlin compiler wants to generate getter/setter properties. for example, I've got this error because I didn't mention @Rule annotation with @get:Rule.

    If we annotate properties like this with @get:... or @JvmField it could solve the problem.

    @get:Rule
    var mActivityRule = ActivityTestRule(MainActivity::class.java)
    

    Or

    @Rule
    @JvmField
    var mActivityRule = ActivityTestRule(MainActivity::class.java)
    

    @JvmField instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field.

提交回复
热议问题