Closed cristan closed 8 months ago
Hi, to eliminate the conflict between the MockK and the Kover, try to add all OkHttp classes to the instrumentation exclusions
testOptions {
unitTests.all {
kover {
excludes = ['okhttp3\\..+']
}
}
}
It's a little weird that this is needed, but excluding OkHttp classes indeed works.
Another instance where mocking okhttp stuff is broken by kover:
@Test
fun `test mocking proceeding a chain`() {
val testChain = mockk<Interceptor.Chain>()
val argument = slot<Request>()
every { testChain.proceed(capture(argument)) }.returns(mockk())
}
This gives this error:
java.lang.VerifyError
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:167)
at io.mockk.proxy.jvm.transformation.JvmInlineInstrumentation.retransform(JvmInlineInstrumentation.kt:28)
Even excluding all okhttp classes doesn't resolve this issue (tested on Kover 0.5.0-RC2).
@shanshin, your recommended workaround isn't working with Kover 0.5.0. After trying different patterns, I switched the coverage engine to JACOCO and it works. The issue seems to be with the kotlinx.kover.api.CoverageEngine.INTELLIJ
, which is the default.
Here's all I added to my build.gradle.kts
that fixed it:
kover {
coverageEngine.set(kotlinx.kover.api.CoverageEngine.JACOCO)
}
Does swapping the coverage engine basically make Kover no more useful than using JACOCO directly?
@foo4u, in version 0.5.0
, the format of filters for classes has changed. Now, instead of specifying a regular expression, you can use only wildcards *
and ?
.
Therefore, now you can exclude OkHttp from instrumentation like this:
testOptions {
unitTests.all {
kover {
excludes = ['okhttp3.*']
}
}
}
Thanks for providing a workaround; this is affecting us as well - would love to get to the bottom of it.
Can confirm this also happens to us with the following config on 0.5.1
kover {
jacocoEngineVersion.set("0.8.8")
generateReportOnCheck = true
disabledProjects = setOf(":di", ":icons", ":test")
instrumentAndroidPackage = false
runAllTestsForProjectTask = false
}
Can confirm workaround is still working for 0.5.1
. Kotlin DSL fix, for anybody not using groovy:
android {
......
testOptions {
unitTests.all {
it.extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
excludes = listOf("okhttp3.*")
}
}
}
}
There are two ways to avoid this problem:
Closed in favor of #418
Tested on Kover 0.4.4:
Dependencies:
Tests:
testMockingResponse()
fails here with this stacktrace:This doesn't happen when I don't add Kover as a plugin. Surprisingly enough,
testMockingRequest()
always succeeds, so there's something in in mockingResponse
which goes wrong which doesn't happen when mockingRequest
.