Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JUnit-Tests using Mockito fail when running all of them(JUnit-Tests using Mockito fail when run from root-"folder")
JUnit-Tests using Mockito fail when running all of them [message #1795001] Wed, 12 September 2018 13:40
Michael Moser is currently offline Michael MoserFriend
Messages: 33
Registered: October 2012
Location: Z├╝rich, Switzerland
I have an odd issue that I can't explain to me:

I have a Maven project which compiles and runs fine.

* Run as ... => Maven test also runs fine - all JUnit tests execute ok.
* If I right-click on any JUnit-test individually and choose Run as ... => JUnit Test that unit-test runs fine. This works for all of them.
* If I right-click on any package (in package explorer) and choose Run as ... => JUnit Test then all tests in that package also run fine. This also holds for all packages (containing any unit tests, i.e. all under src/test/java).

But: if I select the folder src/test/java or the "root"-folder of all my packages and choose Run as ... => JUnit Test in order to run ALL JUnit tests in all test-packages in one single go, then about half of these unit-tests fail with the Exception:

java.lang.NoClassDefFoundError: org/mockito/Mockito
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.RunBefores.evaluate(
at org.junit.runners.ParentRunner.runLeaf(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: java.lang.ClassNotFoundException: org.mockito.Mockito
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 24 more

The run-config in all the above cases is always exactly the same! I have searched left and right but I can't find the reason for this! Mockito *is* on the classpath, so why can't the TestRunner find or instantiate that class?

To make this even stranger: I am observing this in ONE of three projects. In the other two I can run ALL tests in one go as described above without problem, only in this project many tests fail with this strange class-not-found exception.
I also compared the run-config of all of them in detail and they are identical (except name and project folder name, of course).

Any ideas or hints?
Previous Topic:Could someone help me create a commit?
Next Topic:Kitchen Cabinets Buying Guide
Goto Forum:

Current Time: Tue Nov 13 21:08:48 GMT 2018

Powered by FUDForum. Page generated in 0.01879 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top