Running spock unit tests with Maven

This answer is purely supplemental to @PeterNiederwieser’s answer. In it he mentions that you can configure the name pattern used by Surefire. Here is an example of what worked for me:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
        <includes>
            <!-- By default only files ending in 'Test' will be included, so also include support for Spock style naming convention -->
            <!-- Oddly enough for Groovy files, *Spec.groovy does not work, but *Spec.java does -->
            <include>**/*Test.java</include>
            <include>**/*Spec.java</include>
        </includes>
    </configuration>
</plugin>

Source

As I mention in the comments, I’m not sure why **/*Spec.groovy didn’t work, but I’m happy to be able to use the normal Spock convention here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)