Sergey Pauk Sergey Pauk - 1 year ago 72
Groovy Question

Create and jump to Spock unit test for a Java class in Idea IDE

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.

Answer Source

Figured out by myself the steps to make it work:

  1. Add the following plugins to the POM file:

  2. Create src/test/groovy directory

  3. Install GMavenPlus IntelliJ Plugin
  4. If Idea still doesn't see 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).

P.S. command line mvn clean test also works correctly running both JUnit and Spock.