I have a gradle project in kotlin using xml(javax.xml.bind:jaxb-api:2.3.1). I want to test my parsing logic , hence I need to mock my Node(org.w3c.dom.Node). How ever while mocking I am facing this error.
io/mockk/proxy/jvm/advice/jvm/JvmMockKProxyInterceptor java.lang.NoClassDefFoundError: io/mockk/proxy/jvm/advice/jvm/JvmMockKProxyInterceptor
at java.xml/org.w3c.dom.Node$Subclass0.getNodeName(Unknown Source)
My Code
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.0"
application
}
group = "me.shantiswaruptunga"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("javax.xml.bind:jaxb-api:2.3.1")
testImplementation(kotlin("test"))
testImplementation("io.mockk:mockk:1.12.4")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClass.set("MainKt")
}
XMLTest.kt
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Test
import org.w3c.dom.Node
class XmlTest {
@Test
fun test2() {
val node1 = mockk<Node>()
every { node1.nodeName } returns "x"
}
}
The same code was working with jdk 8 kotlin 1.4.31 I referred this mockk github issue but couldn't figure out the problem
Which version of gradle did you use? it might be important to check compatibility https://docs.gradle.org/current/userguide/compatibility.html.
Otherwise I used your example in a blank project creating with intellij and curiously I don't have this problem. This test case worked fine. code example
Two scenarios:
Problem has been resolved by a recent update of io.mockk:mockk library(or update on its library dependencies)
Problem is not identifiable with code example you provided