Is there a way to create and jump to Spock unit test for an application written in Java in Idea IDE ( it's working fine for a Groovy app )? The project is Maven based if it matters.
Reason: I'd like to use Spock framework to test my Java app.
CTRL + SHIFT + T is the default shortcut for unit test creation / navigation (at least on Windows). It can be checked/changed from File
-> Settings
-> Keymap
then in the tree select Navigation
-> Test
(you can also filter the key map to find it easier)
This opens a dedicated popup which allow you to either create a new unit test, or jump to existing ones (if any).
This goes for groovy...
... or java
Figured out by myself the steps to make it work:
Add the following plugins to the POM file:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <includes> <include>**/*Test.java</include> <include>**/*Spec.java</include> </includes> </configuration> </plugin> <plugin> <groupId>org.codehaus.gmavenplus</groupId> <artifactId>gmavenplus-plugin</artifactId> <version>1.5</version> <executions> <execution> <goals> <goal>addTestSources</goal> <goal>testCompile</goal> </goals> </execution> </executions> </plugin>
Create src/test/groovy
directory
src/test/groovy
as a source directory you could delete all the Idea project files from you hard-drive and import your Maven project again After that CTRL + SHIFT + T will offer you to create new tests either in src/test/java
(should be chosen for JUnit tests) or in src/test/groovy
(should be chosen for Spock tests).
PS command line mvn clean test
also works correctly running both JUnit and Spock.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.