-
Notifications
You must be signed in to change notification settings - Fork 179
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
NoClassDefFoundError when using mocks and running spek from IntelliJ on a Windows machine #563
Comments
That's weird, I've used both libraries and seem to work fine for me. Can you share your build script? Or better yet a sample project reproduces the issue? |
Sure. Here is a project allowing to reproduce the problem consistently: https://github.com/jcornaz/spek-mock-bug Again, don't run Steps to reproduce Project JDK IntelliJ Kotlin plugin Spek Framework plugin |
With the hope it helps, here are more information I've found:
|
@jcornaz I cloned the project, tried running the tests via gradle and intellij - everything passed. Adding |
But we consistently reproduce the problem on 3 different machines and 3 different projects. Are you on Windows? Did you use the same IntelliJ version? Did you use the gutter icon in IntelliJ? |
My windows is not setup for development. I have the same version of IJ and the spek plugin. Looking back at the main post, this looks interesting: |
None of our projects are Android projects. So it is definitely not the problem. P.S: And it would concern only Mockito, not MockK anyway. |
EDIT: This message has been moved to a separate issue: #568 |
@jcornaz Can you file that as a separate issue? |
Weird, have you reported to the mockito team?
I don't have it unticked. Can you run |
No because:
My point is: Don't look too much in that direction. Since the problem is reproducible in non-android projects, it is very unlikely that there is any correlation between this message and the bug reported here.
So that's why you don't reproduce the problem. Untick it, and you should be able to reproduce it. Please let me add that we need to untick that box in at least one of our project, which is a maven project and for which delegating to maven is really too slow.
|
Oops sorry double negatives. I don't have it ticked. |
Is there a difference between running the tests from the IJ and gradle? |
Yes. From gradle it works as expected. Not from IJ. Please notice that running all test from IJ also works as expected. Only running from the gutter icon does not work. |
Interesting, it may be a problem with your IJ setup. Have you tried re-installing the spek plugin? If that doesn't work can you test with a vanilla IJ + spek plugin only (it may be conflicting with some other plugin)? |
No. But since we reproduce the problem on 3 different installations, I really doubt that it would make any difference. I will try however.
I will try and keep you updated. EDIT: Disabling all downloaded plugins (except Kotlin and Spekframework) didn't help |
I just cloned your bug-repository and ran the tests via the different methods successfully on
Might be related to Windows only then?! |
That's our best hypothesis I guess... I wonder how it could be related to the operating system, but I have no better clue. I just tried with a vanilla IJ + Spekframework plugin. And I still reproduce the bug:
|
It does seem related to the operating system. I am not able to reproduce the bug on a Linux VM. |
I can confirm the current findings: The issue with running the spec from the gutter icon seems to be an issue with Windows as OS - as opposed to Linux in my case, where the test runs without issue. On windowsI have almost exactly the same environment as @jcornaz (except for a newer jdk): Project JDK IntelliJ Kotlin plugin Spek Framework plugin On linuxProject JDK IntelliJ Kotlin plugin Spek Framework plugin |
tl;dr workaroundIn the run configuration, add the following VM option:
@jcornaz @raniejade I believe I may have found the root cause of this issue. Apologies in advance for the long post; I've been banging my head against this for what feels like forever.
I don't know if this is something that can be fixed from the Spek plugin or not, but I'll poke around a bit more now that I know what to look for. |
I can confirm that the workaround of adding I tried to set the parameter in the custom vm options, in order to not have to set it in the various launch configurations. It didn't work though. I guess the issue (hopefully) taken care of in #577 overrides that setting. |
@ursjoss @floralvikings @jcornaz Have you looked in the console (within IJ) what paremeters IJ is passing to the jvm when running the tests? I suspect something passed there overrides the tmp dir property. |
@raniejade I don't see any obvious override in the console. Do you think that #577 would not solve the issue? By the way: Adding |
This is interesting: https://stackoverflow.com/a/29716813.
Looking at this, MockK writes the jar in a java agent - which may not see the env variables? |
I experimented a bit more. In analogy to @floralvikings comment 7 days ago, I created the following two classes (in two separate packages, that I left out here):
Not surprisingly the JUnitTest prints the expected temp path ( Running the Spek variant produced different outcomes, depending on how I triggered the test.
Presumably on the command line the TMP environment variable can be accessed correctly while this seems not be the case from within the spek runner in IntelliJ. Comparing the two commands running TmpSpec ( (a) right click on package and (b) from gutter icon ) illustrated a few differences that may be noteworthy:
Maybe the spek runner should also add the temp path explicitly. |
@ursjoss wow, thanks for a detailed investigation! Spek is definitely doing something different.
It's not setting the path here, |
@ursjoss do you have this option ticked for the spek run configuration? |
does ticking it fix the problem? |
Yes! |
🎉 fix is a one liner 😂. Anyway, in the meantime you can set the default for Spek 2 - JVM template via the ui. |
Excellent, thank you @raniejade. |
Awesome! I was so close to figuring it out too, didn't even think of looking at that field 😞 Thanks for the awesome research and quick turnaround @ursjoss and @raniejade! |
There is also an effort from the MockK team to fix this issue mockk/mockk#239 |
Hello,
Please consider the following test (using MockK):
It runs fine from gradle (
graldew test
). But running the test from IntelliJ fails with:Please also note that it doesn't concern only Mockk. Using Mockito also fail:
And finally also note that running the Junit5 equivalents works just fine, even when triggered from IntellIJ.
The text was updated successfully, but these errors were encountered: