Reputation: 588
My stack:
We would like to start writing tests in Spock testing framework. I followed this howto, but I was not successful. My spock tests are not running when I try to run all of my tests.
I am able to run one test. I can "right-click" on test and run it. But if I try to run whole groovy package (or some package under Java package) it will not run those groovy tests. It will not run means following error:
Jul 24, 2019 8:33:47 AM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests
java.lang.NoClassDefFoundError: org/junit/platform/engine/support/discovery/SelectorResolver
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:168)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:155)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
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)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.discovery.SelectorResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more
Jul 24, 2019 8:33:47 AM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests
java.lang.NoClassDefFoundError: org/junit/platform/engine/support/discovery/SelectorResolver
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:62)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:168)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:155)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
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)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.discovery.SelectorResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more
Can someone explain why is it possible?
Spock test:
class TelephoneTest extends Specification {
def "Should copy correct values from telephone buidler."() {
given:
TelephoneInfoType telephone = telephone().build().toOurType()
expect:
telephone.getCountry() == COUNTRY
telephone.getNumber() == NUMBER
telephone.getType() == TYPE
telephone.getLocation() == LOCATION
}
}
My folder structure:
src/main/java
src/test/groovy
src/test/java
I would like to see tests are running which means: I can right-click folder src/test/groovy
a select run tests.
Upvotes: 2
Views: 5156
Reputation: 67287
This is what I see in IDEA:
So maybe you want to get more specific and share an MCVE, i.e. a full Maven project with a few dummy classes and tests (both Spock and JUnit), on GitHub for me to inspect.
Update: After inspecting and fixing your MCVE in my fork I can explain what was wrong:
Your MCVE folder for Spock tests was 'src/test/spock'. I renamed it to 'src/test/groovy' in order to enable GMavenPlus to find it. This fixes Groovy test compilation.
In your POM you manually overrode the dependency versions for three JUnit Jupiter artifacts, but mvn help:effective-pom
showed me that some others still were on 5.3.2 while your version was 5.5.1. I am not sure why you think you need to update them other than wishing to be bleeding edge and always use the latest version. Anyway, the effective POM also shows that there are these JUnit-related version properties in your parent POM:
<junit-jupiter.version>5.3.2</junit-jupiter.version>
<junit.version>4.12</junit.version>
More exactly, those properties are from your parent POM's own parent POM. The rest was easy: Just override the relevant property in your own POM:
<properties>
<junit-jupiter.version>5.5.1</junit-jupiter.version>
</properties>
Now run mvn clean test
and see that both JUnit and Spock tests are being compiled and run. Running the tests from IntelliJ IDEA like in my screenshot above also works now.
I also sent you a pull request via GitHub.
Upvotes: 8