4

I've been trying to set up Maven to run my Spock (0.7) tests but to no avail. I've been trying to use groovy-eclipse-compiler as gmaven which is refered to in the Spock documentation is no longer recommended according to its' website. The relevant section of my POM:

<plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <verbose>true</verbose>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.8.0-01</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-batch</artifactId>
                    <version>2.1.8-01</version>
                </dependency>
            </dependencies>
        </plugin>

When I run mvn test I get:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Any ideas why maven/surefire just isn't picking up my tests? As the section of the website suggests I've ensured there is a blank file present in src/test/java

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
Keir
  • 440
  • 6
  • 15

2 Answers2

7

Surefire will pick up Spock tests automatically as long as the test classes match Surefire's naming conventions (*Test etc. by default). First you should check if the test classes actually get compiled and are present under target/test-classes. If not, there is probably something wrong with how you set up the Groovy compiler.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
0

If you are using an IDE like Idea or Eclipse, it may happen that building the project from the IDE successfully compiles your test classes.

  1. To ensure that a maven build is working and properly configured issue a mvn clean verify from the command line.
  2. Check if the build compiled the test classes at target/test-classes

If the test classes were not compiled, then the problem is a misconfiguration of the gmavenplus-plugin responsible for compiling the groovy code.

More than probable, you are missing the execution goals part:

<plugin>
  <groupId>org.codehaus.gmavenplus</groupId>
  <artifactId>gmavenplus-plugin</artifactId>
  <version>1.4</version>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>testCompile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Daniel Cerecedo
  • 6,071
  • 4
  • 38
  • 51