Prometheus Blogs

Configuring Spock integration tests, written in Groovy, with the Maven failsafe plugin

07/05/2016

Maven failsafe plugin works fine with the normal JUnit test cases. But what if you wanted to use the Spock framework for your integration tests? This post will focus on the configuring Spock tests written in Groovy because the maven build configuration is tricky when it comes to Groovy. Initially, I used a “.groovy” file extension in the maven failsafe plugin configuration Include entry but the Spock tests did not run at all in my experience. After trying out several things the only way I found a solution to the problem was to add another Include configuration entry with a “.java” file extension for the same Spock Groovy class and it worked. Here’s the relevant part of the maven POM build configuration shown below.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <includes>
                    <include>**/*Spec.groovy</include>
                    <include>**/*Spec.java</include>
                </includes>
            </configuration>
…
</build>
Reader Comments
  1. Ittai said... around about 2 years ago
    Hi, Did you end up finding why or filing a bug? I just stumbled on to this since we have a mixed Java/Scala codebase and so our maven config always contained both above lines. New OSS project with only Scala surfaced this...
  2. Sunil Bhaskarla said... around about 2 years ago
    Hi Ittai, I don't know the real reason but my only guess was to realize Groovy complied into Java so I added an explicit instruction. And I didn't file a bug. Not a bad idea to create one if one doesn't exist by now.
Leave a Comment

Back