Skip to content

Absent Code attribute in method that is not native or abstract in class file android/content/Context #91

@AlexeyKolosov

Description

@AlexeyKolosov

Hi, I'm using your hidden API, but having an issue with tests:
For unknown reason I can't mock android classes, such as Content in my Android project unit tests. So it gives error:

"Absent Code attribute in method that is not native or abstract in class file android/content/Context"
The example of a functionality and a test:

class SomeClassWithAndroidClass(
    private val context: Context // this even is not used, but fails
) {
    val myField = 42
}

class SomeClassWithAndroidClassTest {
    @Test // import org.junit.jupiter.api.Test
    fun `Verify field`() {
        val someClassWithAndroidClass = SomeClassWithAndroidClass(mockk())
        assert(someClassWithAndroidClass.myField == 3)
    }
}

I use jupiter version 5.8.1, junit platform version 1.8.1, mockk version 1.12.0, kotlin version 1.6.21 in build.gradle I have:

android {
    testOptions {
        unitTests.returnDefaultValues = true
        unitTests.all {
            useJUnitPlatform()
        }
    }
   ...

     compileSdkVersion 30
     defaultConfig {
         minSdkVersion 28
         targetSdkVersion 30
     }
   ...
}

Maybe you have an idea, what can resolve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions