使用位于src / test / java中的Maven运行Spock测试

时间:2014-12-11 08:28:38

标签: maven groovy spock surefire gmaven

我试着一些Spock测试:

MyTest.groovy
ConfTest.groovy

是Spock测试。它们位于src/test/java,当我运行验证时,它们会被跳过。当我将它们放入src/test/groovy Maven 时,找到它们。我可以配置 Maven ,以便在src/test/java时找到它们吗? 我的Maven配置是:

 <!-- 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 个答案:

答案 0 :(得分:1)

在插件级别将其添加到GMaven配置中:

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

更新或者在执行级别添加此内容(请参阅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>