-
-
Notifications
You must be signed in to change notification settings - Fork 339
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
Bug: MockK is not runnable together with PowerMockito #79
Comments
Looks like the agent is not attachable. I know this is for windows, but try to put attach.so (I don't know how indeed it's called for macosx) in jdk/jre/lib to a PATH. https://stackoverflow.com/questions/39420830/virtualmachine-attach-failing (read show more comments) |
I've just realised that removing PowerMockito doesn't throw that. |
Oh, ok just was writting to try that. |
So it's powermock issue, because I was fixing integration with mockito already. |
Sorry to do another comment. |
Yeah I know, but attach.so should be in Linux and Mac OS X |
Anyway I'd like to reproduce and fix it if possible. Thanks for reporting |
Sure, what else would you need? |
I think I have enough information for now |
Hi, MockK : 1.8.3 |
Hi, no progress so far. If will have some spare time will check that |
We began integrating Mockk into our Android SDK over at Flybits however this issue is holding us back since many existing unit tests require PowerMock stubbing functionality. |
@karolzdebel
|
Running the JavaClassTest below with the given gradle throws:
Gradle:
Test class:
|
At least I found some workaround. Provided example do not throw any exception. Do not know if it will work in general.
|
I played a bit more. Following code is printing for me
There is no MockK involved here at all and thus it should not load. Somebody should check if these workarounds are really working. If yes I can submit PR to PowerMock to include this as a permanent solution. The general conclusion is that MockK lacks integration tests with other frameworks. |
@oleksiyp Not worked for my project until I changed the code as below :
This is like the case that Robolectric will encounter also. |
Hi @oleksiyp !
Without problem! Is this issue maybe gone? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as |
Hello, In case it might help someone else, I had the same issue and it was caused by With these versions:
|
Closing this as looks like there's not much to do about this specifically other than making sure Mockk plays well with other testing and mocking frameworks. |
Prerequisites
Expected Behavior
Mocking a static method
Failure Information (for bugs)
java.lang.ExceptionInInitializerError
at my.package.ConfigUseCaseTests.getConfigs_fromJson(ConfigUseCaseTests.kt:33)
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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
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 com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: io.mockk.MockKException: Failed to load plugin io.mockk.proxy.jvm.JvmMockKAgentFactory
at io.mockk.impl.JvmMockKGateway.(JvmMockKGateway.kt:152)
at io.mockk.impl.JvmMockKGateway.(JvmMockKGateway.kt:138)
... 29 more
Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@1c72da34
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:377)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:351)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:319)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:305)
at io.mockk.proxy.jvm.MockKInstrumentation.(MockKInstrumentation.java:57)
at io.mockk.proxy.jvm.JvmMockKAgentFactory.(JvmMockKAgentFactory.java:11)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at io.mockk.impl.JvmMockKGateway.(JvmMockKGateway.kt:150)
... 30 more
Caused by: java.lang.reflect.InvocationTargetException
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 net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:372)
... 41 more
Caused by: java.lang.NullPointerException
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:187)
... 47 more
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Minimal reproducible code (the gist of this issue)
I've also tested it with
staticMockk
or any other examples provided but I'm getting the same error.The text was updated successfully, but these errors were encountered: