Groovy Spock installation of the environment

Source: Internet
Author: User

I heard that Spock is a reinforced version of JUnit, today specifically installed, and then the process to share with you. First of all, my Java project is managed with Maven. The eclipse I used was kelper, Kepler. Before you use Spock, you first need to match the groovy environment. Search the Internet, found the groovy Eclipse plugin: http://dist.springsource.org/snapshot/GRECLIPSE/e4.3/index.html Just this installation package is for Kepler. The more advanced version of Eclipse appears to be installed online, and there are no offline installation packages available to download. With this installation package you can match groovy's eclipse environment, but I've also found that some eclipse will not be able to install, the Internet under a new eclipse can be installed, may be related to some of Eclipse plug-ins conflict. Turning on Eclipse's configuration, it's amazing to find that there's a groovy item. Check compiler to find that the supported compiler version is from 1.8.6 to 2.2.2, the higher can not support, is estimated to be related to the groovy plug-in eclipse, if you want to support, you may want to use the updated version of Eclipse. I did not hesitate to choose the latest version of 2.2.2. The following dependencies are added to the pom file,<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>Groovy-all</artifactid>
<version>2.2.2</version></dependency> Next installs the Spock, and finds the corresponding version of the relationship from the Spock wiki. Spock Version | Groovy Version | JUnit Version | Grails Version | Spring Version | | 0.5-groovy-1.6 | 1.6.1-1.6.x | 4.7-4.x | 1.2.0-1.2.x | 2.5.0-3.x | | 0.5-groovy-1.7 | 1.7.0-1.7.x | 4.7-4.x | 1.3.0-1.3.x | 2.5.0-3.x | | 0.6-groovy-1.7 | 1.7.0-1.7.x | 4.7-4.x | 1.3.0-1.3.x | 2.5.0-3.x | | 0.6-groovy-1.8 | 1.8.1-1.8.x | 4.7-4.x | 2.0-2.x | 2.5.0-3.x | | 0.7-groovy-1.8 | 1.8.1-1.8.x | 4.7-4.x | 2.0-2.x | 2.5.0-3.x | | 0.7-groovy-2.0 | 2.0.0-2.x.x | 4.7-4.x | 2.2-2.x | 2.5.0-3.x | | 1.0-groovy-2.0 | 2.0.0-2.2.x | 4.7-4.x | 2.2-2.x | 2.5.0-4.x | | 1.0-groovy-2.3 | 2.3.0-2.3.x | 4.7-4.x | 2.2-2.x | 2.5.0-4.x | | 1.0-groovy-2.4 | 2.4.0-2.x.x | 4.7-4.x | 2.2-2.x | 2.5.0-4.x | found to support 2.2.2, only the version of 1.0-groovy-2.0 can be used. So I did not hesitate to add the following dependencies. <dependency>
<groupId>org.spockframework</groupId>
<artifactId>Spock-core</artifactid>
<version>1.0-Groovy-2.0</version>
</dependency> good, come to a Hello world at once. Package Com.test.groovytest

Import spock.lang.Specification;

Class Addtest extends specification{
Add add = new Add ();
int result;
def "Test add 1 and 2" () {
Given: "There is the number 1 and 2"
ADD.A = 1;
ADD.B = 2;
When: "Add them"
result = Add.add ();
Then: "Result should is 3"
result = = 4;
}
}
This is one of the simplest Spock tests on an adder. But after writing it, you can't run tests in eclipse. The version of JUnit is found to be incorrect and is now replaced with the latest. <dependency>
<groupId>JUnit</groupId>
<artifactId>JUnit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
OK, the test can run in Eclipse. But continuous integration runs inside the command line, MVN Clean compile on the command line and discovering that groovy is not compiled. On the internet to find a bit, you must add plugin in the pom file. Well, add the plugin to the <plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>Gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins> found that the groovy files in the project are still not compiled, the Internet to find, find examples on the web to put groovy files into the new compilation path, the name of the compilation path is src/main/groovysrc/test/ Groovy creates the two paths, moves the groovy file over, and MVN clean test. OK, it's a success. But this time in eclipse found the following error, Plugin execution not covered by lifecycle configuration in StackOverflow find a solution. Add <pluginManagement> in Pom file
<plugins>
<!--This plugin ' s configuration was used to store Eclipse m2e settings
Only. It has no influence on theMavenBuild itself. -
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>Lifecycle-mapping</artifactid>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
Org.codehaus.gmavenplus
</groupId>
<artifactId>
Gmavenplus-plugin
</artifactId>
<versionrange>[1.5,) </versionRange>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement> then we can't find any other problems, we can start to happily write Spock test cases.

Groovy Spock installation of the environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.