【Groovy】Spock with Maven

已经在项目里使用Groovy/Spock做测试框架了,感觉和Maven结合在一起还是挺好用的。

在Maven的pom.xml里引入他们还是挺方便的,第一先要在dependency 里引入

        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.8.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>0.6-groovy-1.8</version>
            <scope>test</scope>
        </dependency>

接着是要在Plugin部分做些配置

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <configuration>
                            <tasks>
                                <taskdef classname="org.codehaus.groovy.ant.Groovyc" name="groovyc">
                                    <classpath refid="maven.test.classpath"/>
                                </taskdef>
                                <mkdir dir="${project.build.outputDirectory}"/>
                                <mkdir dir="${project.build.testOutputDirectory}"/>
                                <groovyc destdir="${project.build.testOutputDirectory}" listfiles="true" srcdir="${basedir}">
                                    <classpath refid="maven.test.classpath"/>
                                </groovyc>

                                <ant antfile="${basedir}/build.xml" target="groovytarget">  
                                    
                                </ant>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ant</groupId>
                        <artifactId>ant-nodeps</artifactId>
                        <version>1.6.5</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.spockframework</groupId>
                <artifactId>spock-maven</artifactId>
                <version>0.6-groovy-1.8</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>find-specs</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.3</version>
                <executions>

                    <execution>
                        <goals>
                            <!--
    <goal>generateStubs</goal>
    <goal>compile</goal>
  -->
                            <goal>generateTestStubs</goal>
                            <goal>testCompile</goal>
                        </goals>

                        <configuration>
                            <debug>true</debug>
                            <verbose>true</verbose>
                            <stacktrace>true</stacktrace>
                            <defaultScriptExtension>.groovy</defaultScriptExtension>
                            <providerSelection>1.7</providerSelection>
                            <source>
                                <fileset>
                                    <directory>${pom.dir}</directory>
                                    <includes>
                                        <include>**/groovy/*.groovy</include>
                                    </includes>
                                </fileset>


                            </source>
                        </configuration>
                    </execution>

                </executions>
            </plugin>
        </plugins>
    </build>

 

 

posted @ 2013-11-12 20:39  卜海清  阅读(1785)  评论(0编辑  收藏  举报