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: 64
Registered: October 2012
Location: Zürich, Switzerland
Member
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 foo.bar.setUp(bar.java:21)
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.RunBefores.evaluate(RunBefores.java:24)
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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: java.lang.ClassNotFoundException: org.mockito.Mockito
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 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:Native library path not working in tomcat
Goto Forum:
  


Current Time: Thu Apr 25 19:07:30 GMT 2024

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

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

Back to the top