-
-
Notifications
You must be signed in to change notification settings - Fork 366
Version 1.14.0 introduces class redefinition failed: invalid class
in Android local tests
#1375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@sgerke-1L @marcelstoer this looks related to the switch from |
@bddckr can you please see #1118 (comment) for a way of finding out what exactly the JVM has issues with. |
While trying to do that to provide more info, I've had to restart Android Studio. Once restarted, I could no longer reproduce 🤔 I've definitely synced the project in the IDE when I did my changes, and confirmed that the attempt to use newer Byte Buddy versions also applied before restarting. Sorry for wasting your time, closing this! |
No worries, please report back if the issue re-occurs! |
Just as I get this pushed to my CI pipeline, it fails again. That helped me find the reason why I wasn't able to reproduce anymore: It only reproduces if I run the test with code coverage enabled! Not via Android Studio/IntelliJ's android {
buildTypes {
debug {
enableUnitTestCoverage = true
}
}
} So perhaps this is an issue only when JaCoCo is applied? As a test, I've set Thanks a lot for handling these issues, btw - much appreciated! |
Got the additional info via tasks.withType<Test>().configureEach {
jvmArgs("-Xlog:redefine+class*=trace:stdout")
} Details
|
It looks like jacoco is doing also instrumentation to track code coverage, which now interferes with mockk's instrumentation. |
It's happen to me also with this code: @BeforeEach
fun beforeEach() {
mockkStatic(RandomStringUtils::class)
}
@AfterEach
fun afterEach() {
unmockkStatic(RandomStringUtils::class)
}
@Test
fun `should ...`() {
every { RandomStringUtils.secure().nextAlphanumeric(any()) } returns REFERRAL_CODE
...
verify(exactly = 1) { RandomStringUtils.secure().nextAlphanumeric(8) }
} Error:
Where previously it's fine with Info |
Same issue here on
|
Thanks for providing the helpful examples and debug output. Based on the examples, I was able to extract a reproducer test-case and a proposed fix. There seems to be an issue with decorate when it is used for static intercepts. I don't fully understand the issue, especially because it only seems to manifest in conjunction with jacoco, but I suspect it has to do with how static class members are initialized. I've put up #1376 as one way to fix it. There is another mentioned in the PR comment. I'd appreciate feedback on what to use. |
Use redefine if mockkStatic is used (fix candidate for #1375)
I can confirm that this is fixed by 1.14.2. Thanks a lot! |
On MockK version 1.13.17, this code in the
test
folder of an Android library project works:But in MockK 1.14.0 it fails:
Versions used:
I've also tried depending on
net.bytebuddy:byte-buddy
andnet.bytebuddy:byte-buddy-agent
in this project to change the resolved version that's used. I then set it to the latest available Byte Buddy version -1.17.5
. This didn't change anything - it's still failing the same way.The text was updated successfully, but these errors were encountered: