Spock tests doesn't run from maven

2,341 views
Skip to first unread message

Artem Nikitin

unread,
Sep 16, 2013, 8:39:51 AM9/16/13
to spockfr...@googlegroups.com
I start to use Spock in Java project with maven. And found some troubles. When I run it via "mvn test"  tests don't execute, but maven report that "build success". Reason of this because tests doesn't compile.  If look to "target" directory then .class files for tests doesn't exists. If run test from IDE all work fine. Also test .class files can be found in target directory and "mvn test" works well. How I can fix this and make work all time ?

Contents of pom.xml:

<dependencies>
  <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
</dependency>
<dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.3</version>
    </dependency>
    <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
    </dependency>
    <dependency>
      <groupId>org.spockframework</groupId>
      <artifactId>spock-core</artifactId>
      <version>0.6-groovy-1.8</version>
      <scope>test</scope>
    </dependency>    
   
  </dependencies>
  
   <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.3</version>
        <configuration>
          <providerSelection>1.7</providerSelection>
        </configuration>
        <executions>
          <execution>
          <phase>test</phase>
            <goals>          
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.gmaven.runtime</groupId>
            <artifactId>gmaven-runtime-1.7</artifactId>
            <version>1.3</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>
        </dependencies>
      </plugin>   
      
    </plugins>
        
  </build>
 

Peter Niederwieser

unread,
Sep 16, 2013, 8:51:00 AM9/16/13
to spockfr...@googlegroups.com
My first guess is that you haven't configured Groovy test compilation correctly (phase `test` might be too late to compile the tests). I recommend to compare your project/POM to https://github.com/spockframework/spock-example. I also recommend to use Spock 0.7 (although that's not the source of the problem). And `junit` should probably have `test` scope.

Cheers,
Peter

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spockframewor...@googlegroups.com.
To post to this group, send email to spockfr...@googlegroups.com.
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/groups/opt_out.

signature.asc

Artem Nikitin

unread,
Sep 16, 2013, 10:15:34 AM9/16/13
to spockfr...@googlegroups.com
Thanks for support Peter. I fixed my troubles and hope it can save some time for others ) 

In my cases helps adding to "build" section of pom.xml this part :

         <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <compilerArgument>nowarn</compilerArgument>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.5.1-1</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-batch</artifactId>
                    <version>1.8.0-03</version>
                </dependency>
            </dependencies>
        </plugin>

Peter Niederwieser

unread,
Sep 16, 2013, 10:24:25 AM9/16/13
to spockfr...@googlegroups.com
I think that's an *alternative* to using the GMaven plugin. The latter should certainly work as well, as long as it's configured correctly (see POM for spock-example project).

Cheers,
Peter

signature.asc

Marcin Zajączkowski

unread,
Sep 16, 2013, 10:44:51 AM9/16/13
to spockfr...@googlegroups.com
On 2013-09-16 16:15, Artem Nikitin wrote:
> Thanks for support Peter. I fixed my troubles and hope it can save some
> time for others )
>
> In my cases helps adding to "build" section of pom.xml this part :
>
> <plugin>
> <artifactId>maven-compiler-plugin</artifactId>
> <version>2.3.1</version>
> <configuration>
> <compilerId>groovy-eclipse-compiler</compilerId>
> <compilerArgument>nowarn</compilerArgument>
> </configuration>
> <dependencies>
> <dependency>
> <groupId>org.codehaus.groovy</groupId>
> <artifactId>groovy-eclipse-compiler</artifactId>
> <version>2.5.1-1</version>
> </dependency>
> <dependency>
> <groupId>org.codehaus.groovy</groupId>
> <artifactId>groovy-eclipse-batch</artifactId>
> <version>1.8.0-03</version>
> </dependency>
> </dependencies>
> </plugin>

There is also a complete working example how to integrate Groovy and
Spock (groovy-eclipse-compiler) with a Java application built with Maven:
https://github.com/szpak/code-examples-and-poc/blob/master/parametrized-spock-pit-poc/pom.xml

Nevertheless it is much easier (shorter) to do the same with Gradle :).

Marcin
--
http://blog.solidsoft.info/ - Working code is not enough

Leonard Brünings

unread,
Sep 19, 2013, 6:51:20 PM9/19/13
to spockfr...@googlegroups.com
I would certainly recommend using the "groovy-eclipse-compiler" instead of gmaven, the latter caused some weird behavior where the eclipse compiler works,
especially with groovy 2.+ And if you are using eclipse anyway I then it makes even more sense.

As for the op question, I would like to add that surefire with it's default settings only includes files that end "Test" so if you use "Spec" as some might be tempted
you would have to change the surefire include settings to get them to work, or just rename them.
Reply all
Reply to author
Forward
0 new messages