ClassNotFoundException trying to run JUnit 5 test

Answered

Hi,

I created a simple test like the one here: http://junit.org/junit5/docs/current/user-guide/#writing-tests

When I try to run that test in IntelliJ, I see the error output below. Any idea what that means and how to get tests to run?

I have a pom.xml that declared dependency on junit-jupiter-api:5.0.0-M3, so it compiled fine.

IntelliJ IDEA 2016.3.4

Rob

 

Mar 10, 2017 3:54:32 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFO: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage]
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runners/model/RunnerBuilder
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.populateEngineDescriptor(JUnit4DiscoveryRequestResolver.java:88)
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.resolve(JUnit4DiscoveryRequestResolver.java:49)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:47)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:109)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:79)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:47)
< 8 internal calls >
Caused by: java.lang.ClassNotFoundException: org.junit.runners.model.RunnerBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 14 more

0
8 comments

Try the latest version from http://www.jetbrains.com/idea/download/index.html.

Make sure all these 3 dependencies are in the classpath: http://stackoverflow.com/a/42724223/104891.

0

Okay, I upgraded to the newest IntelliJ: 2016.3.5. And I can confirm those exact 3 packages are on my classpath. But I still get the error. Any other ideas?

Rob

0

It's working now.

While this class is JUnit 5, there are also many old JUnit 4 tests around. I changed the old junit dependency from 4.0 to 4.12 and now everything works.

0

Thanks for the information.

0

My problem was I had to downgrade from junit jupiter 5.2.0 to 5.0.0 M4 because intellij community edition only supports up to that milestone currently (7/23/18) http://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea Hopefully this can solve someone else's problem. 

1

Coltonbgrange
Thanks, it helped me

0
Avatar
Permanently deleted user

I have faced with similar issue on jupiter 5.5.0-M1 and helped adding missing junit-platform-commons dependency

0

Please sign in to leave a comment.