Can't find tests (JUnit 5)

Answered

When I attempt to run an entire folder of unit tests, I am told that "No tests were found". I am told that "Tests were not found in module [OMITTED MODULE NAME]. Use module [OTHER OMITTED MODULE NAME] instead." I have changed and applied the classpath to the specified module under Run -> Debug Configurations, but I every time I run the folder again it reverts to the prior classpath.

When I attempt to run a single unit test file, I get the following stack trace:

Feb 06, 2018 2:01:43 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: [OMITTED JAVA FILE NAME]
at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:71)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:70)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.lambda$resolveSelectors$2(DiscoverySelectorResolver.java:59)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:58)
at org.junit.jupiter.engine.JupiterTestEngine.resolveDiscoveryRequest(JupiterTestEngine.java:68)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:82)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:48)
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)

 

As far as I can tell, my setup is identical to that of my coworkers, who are not having any issues.

 

IntelliJ IDEA version: 3.4

OS: Mac OS X

Relevant Gradle dependencies:

testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.2'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.2'
9 comments
Comment actions Permalink

Please try File | Invalidate Caches | Invalidate and Restart, then rebuild the project.

If the issue persists, please provide the sample project to reproduce.

3
Comment actions Permalink

I've tried your suggestion, to no avail. Unfortunately, I'm not legally allowed to provide the project in question. Do you have any other ideas?

0
Comment actions Permalink

You probably don't need this dependency:

testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.2

since IntelliJ IDEA 2017.3.4 comes with the up to date JUnit version bundled.

See http://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea:

> // Only needed to run tests in a version of IntelliJ IDEA that bundles an older version

Fix the dependencies, delete .idea directory, reimport the project from Gradle.

0
Comment actions Permalink

It turns out I was using a different JDK version from my teammates. I downgraded to what they were using and it seems to work now.

0
Comment actions Permalink

I have same problem. It's seems it doesn't work with JDK 10.

0
Comment actions Permalink

I have similar issues with Java 11 (if that is, in fact, the root cause).

2
Comment actions Permalink

This problem appeared in a project that stored its junit-dependencies explicitly (no maven or whatsoever), and somehow the module dependencies were removed and replaced by the IDE's bundled JUnit 5. I removed that one and restored the dependencies on the project's JARs of these.

0
Comment actions Permalink

Please create an issue at YouTrack: https://youtrack.jetbrains.com/issues with project sample attached. Thank you.

0
Comment actions Permalink

Found reason o https://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea

Idea will download specific versions of JUnit platform dependencies specified  in mvane/gradle.

 

 

1

Please sign in to leave a comment.