Run Spock tests with Maven located in src/test/java

1.8k views Asked by At

I java some Spock tests:

MyTest.groovy
ConfTest.groovy

which are Spock tests. They are located in src/test/java and when I run verify, they are skipped. When i put them in src/test/groovy Maven find them. Can I configure Maven to find them when they are in src/test/java? My Maven configurations are:

 <!-- Groovy compilation -->
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <providerSelection>1.8</providerSelection>
                    <source/>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generateStubs</goal>
                            <goal>compile</goal>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.gmaven.runtime</groupId>
                        <artifactId>gmaven-runtime-1.8</artifactId>
                        <version>1.4</version>
                        <exclusions>
                            <exclusion>
                                <groupId>org.codehaus.groovy</groupId>
                                <artifactId>groovy-all</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>1.8.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.spockframework</groupId>
                        <artifactId>spock-core</artifactId>
                        <version>0.7-groovy-1.8</version>
                        <exclusions>
                            <exclusion>
                                <groupId>org.codehaus.groovy</groupId>
                                <artifactId>groovy-all</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
            </plugin>

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useFile>false</useFile>
                <includes>
                    <include>**/*Test.*</include>
                </includes>
            </configuration>
        </plugin>
1

There are 1 answers

0
kriegaex On

Add this to your GMaven configuration on the plugin level:

<configuration>
    <testSources>
        <testSource>
                <directory>${pom.basedir}/src/test/java</directory>
                <includes>
                    <include>**/*.groovy</include>
                </includes>
        </testSource>
    </testSources>
</configuration>

Update: Or add this on the execution level (see groovy:testCompile goal documentation):

<execution>
    <goals>
        <goal>testCompile</goal>
    </goals>
    <configuration>
        <sources>
            <source>
                <directory>${pom.basedir}/src/test/java</directory>
                <includes>
                    <include>**/*.groovy</include>
                </includes>
            </source>
        </sources>
    </configuration>
</execution>