Please answer the following questions for yourself before submitting an issue.
Upgrading from 1.10.2 to 1.10.3 should not break existing code.
Code does not execute anymore due to reflective use of Kotlin 1.4 API.
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Please provide detailed steps for reproducing the issue.
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
// -----------------------[ YOUR STACK STARTS HERE ] -----------------------
'void kotlin.jvm.internal.FunctionReferenceImpl.<init>(int, java.lang.Object, java.lang.Class, java.lang.String, java.lang.String, int)'
java.lang.NoSuchMethodError: 'void kotlin.jvm.internal.FunctionReferenceImpl.<init>(int, java.lang.Object, java.lang.Class, java.lang.String, java.lang.String, int)'
at io.mockk.impl.JvmMockKGateway$mockTypeChecker$1.<init>(JvmMockKGateway.kt)
at io.mockk.impl.JvmMockKGateway.<init>(JvmMockKGateway.kt:97)
at io.mockk.impl.JvmMockKGateway.<clinit>(JvmMockKGateway.kt:172)
// -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class MockkTest {
@Test
fun test() {
val mockk = mockk<Mocked> { every { hi() } returns "Hello world" }
assertEquals(mockk.hi(), "Hello world")
}
}
class Mocked {
fun hi() = "there"
}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
I have similar issue with:
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.50"
testImplementation "io.mockk:mockk:1.10.3-jdk8"
class MockkTest {
class Dependency1(val value1: Int)
class Dependency2(val value2: String)
class SystemUnderTest(
val dependency1: Dependency1,
val dependency2: Dependency2
) {
fun calculate() =
dependency1.value1 + dependency2.value2.toInt()
}
@Test
fun calculateAddsValues() {
val doc1 = mockk<Dependency1>()
val doc2 = mockk<Dependency2>()
every { doc1.value1 } returns 5
every { doc2.value2 } returns "6"
val sut = SystemUnderTest(doc1, doc2)
assertEquals(11, sut.calculate())
}
java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
at io.mockk.impl.JvmMockKGateway$mockTypeChecker$1.<init>(JvmMockKGateway.kt)
at io.mockk.impl.JvmMockKGateway.<init>(JvmMockKGateway.kt:97)
at io.mockk.impl.JvmMockKGateway.<clinit>(JvmMockKGateway.kt:172)
at jp.co.finc.fincapp.ui.billing.MockkTest.calculateAddsValues(MockkTest.kt:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
We're experiencing this with Kotlin 1.3.70 and MockK 1.10.3 on JVM for tests that worked with MockK 1.10.0
I think I have found a fix for this, looks like the behavior for function references changed between kotlin 1.3 and 1.4, will include this in the next release which will hopefully support kotlin 1.3.* again.
Most helpful comment
I think I have found a fix for this, looks like the behavior for function references changed between kotlin 1.3 and 1.4, will include this in the next release which will hopefully support kotlin 1.3.* again.