Fork me on GitHub

Groovy Project with Spock Specifications

Sample minimal configuration for Groovy Project with Spock Specification

Test dependencies for generated contract verification tests

        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>spring-mock-mvc</artifactId>
            <version>2.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.toomuchcoding.jsonassert</groupId>
            <artifactId>jsonassert</artifactId>
            <version>0.4.7</version>
            <scope>test</scope>
        </dependency>

Project configuration for Accurest, Groovy, Spock specifications and stub publishing

            <plugin>
                <groupId>org.springframework.cloud.contract</groupId>
                <artifactId>spring-cloud-contract-verifier-maven-plugin</artifactId>
                <version>${accurest-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>convert</goal>
                            <goal>generateStubs</goal>
                            <goal>generateTests</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <baseClassForTests>hello.BaseAccurest</baseClassForTests>
                    <testFramework>SPOCK</testFramework>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <testSources>
                        <testSource>
                            <directory>${project.basedir}/src/test/groovy</directory>
                            <includes>
                                <include>**/*.groovy</include>
                            </includes>
                        </testSource>
                        <testSource>
                            <directory>${project.build.directory}/generated-test-sources/contracts</directory>
                            <includes>
                                <include>**/*.groovy</include>
                            </includes>
                        </testSource>
                    </testSources>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <includes>
                        <include>**/*Spec.java</include>
                    </includes>
                </configuration>
            </plugin>

Base Specification class

/**
 *
 *  Copyright 2013-2016 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package hello

import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
import spock.lang.Specification

public class BaseAccurest extends Specification {

    def setup() {
        RestAssuredMockMvc.standaloneSetup(new GreetingController())
    }

}