How to run my first Spock test class on Maven/Eclipse

2,575 views
Skip to first unread message

Emmanuel DEMEY

unread,
May 2, 2012, 7:24:21 AM5/2/12
to spockfr...@googlegroups.com
Hi everybody, 

I am quit a newbie of Spock, but I tried to run my first Spock test on Eclipse, and it does not work. 

I installed the Groovy Eclipse plugin, and follow this tutorial :  http://mrhaki.blogspot.fr/2011/01/spocklight-add-spock-support-to-java.html 

I did not specify the spock plugin in my pom.xml file, because I use Maven 3, and this plugin does not work with this version.  But when I run the jUnit Test (Alt + shift + x +t), there is a popup displaying "No jUnit Test found". What am I doing wrong ? 

My Groovy test is part of a Java project. Do I have to convert my Java Project into a Groovy project, like explained in the Haki's tutorial  ?

Thanks a lot. 

Manu

--
Emmanuel DEMEY
Ingénieur Etude et Développement
ATOS Worldline
+33 (0)6 47 47 42 02
demey.e...@gmail.com

Twitter : @gillespie59

Peter Niederwieser

unread,
May 2, 2012, 3:03:45 PM5/2/12
to Spock Framework - User
These are really two questions:

1. How to get up and running with Spock and Maven 3?

The easiest way is to download the spock-example project from GitHub
(https://github.com/spockframework/spock-example/downloads). See the
README file. For Maven 3, remove the spock-maven plugin. This plugin
is purely optional and doesn't work with Maven 3. In that case, make
sure to name the spec classes after the Surefire naming conventions
(e.g. *Test if you haven't reconfigured Surefire). Because the spec
classes in the spock-example project don't follow this convention,
this is a common pitfall. The next version of Spock will hopefully
also provide a plugin for Maven 3. This will require a complete
rewrite of the plugin, but I'm already halfway through.

2. How to get up and running with Spock and Eclipse?

Either follow the instructions in the spock-example README (i.e. use
Gradle to auto-generate the Eclipse project), or check out the
information in the Spock Wiki (http://code.google.com/p/spock/wiki/
GettingStarted#Eclipse). The most common reasons for this not working
are:

* You are using Eclipse <= 3.5 but haven't added the spock-core
sources Jar (see Spock Wiki for more information on this)
* The Groovy Eclipse plugin isn't installed or the installation is
broken
* You are using the spock-core Jar for major Groovy version x (e.g.
1.8) but the Groovy Eclipse plugin is configured to use Groovy major
version y (e.g. 1.7)
* The Eclipse project is missing the Groovy nature (Select project in
Project or Package Explorer -> Context Menu -> Groovy -> Add Groovy
nature). This hint seems to be missing from the Spock Wiki.
* The spec class isn't extending spock.lang.Specification or a
subclass thereof

Make sure to use the latest release version of Spock (spock-core-0.6-
groovy-1.7 or spock-core-0.6-groovy-1.8) and the latest release
version of the Groovy Eclipse plugin. Check the errors tab in Eclipse
and the Eclipse error log. Perform a clean build.

Hope this helps.

Cheers,
Peter

On May 2, 1:24 pm, Emmanuel DEMEY <demey.emman...@gmail.com> wrote:
> Hi everybody,
>
> I am quit a newbie of Spock, but I tried to run my first Spock test on
> Eclipse, and it does not work.
>
> I installed the Groovy Eclipse plugin, and follow this tutorial :http://mrhaki.blogspot.fr/2011/01/spocklight-add-spock-support-to-jav...
>
> I did not specify the spock plugin in my pom.xml file, because I use Maven
> 3, and this plugin does not work with this version.  But when I run the
> jUnit Test (Alt + shift + x +t), there is a popup displaying "No jUnit Test
> found". What am I doing wrong ?
>
> My Groovy test is part of a Java project. Do I have to convert my Java
> Project into a Groovy project, like explained in the Haki's tutorial  ?
>
> Thanks a lot.
>
> Manu
>
> --
> Emmanuel DEMEY
> Ingénieur Etude et Développement
> ATOS Worldline
> +33 (0)6 47 47 42 02
> demey.emman...@gmail.com
>
> Twitter : @gillespie59

Emmanuel DEMEY

unread,
May 3, 2012, 3:57:44 AM5/3/12
to spockfr...@googlegroups.com
Thanks Peter

It works right now. But I have an other question. 

The tests of my existing project is based on TestNG (using a testng.xml file). but Spock use jUnit ? Am I right ? 

How can I mix this 2 testing framework in my pom.xml ? By configuring the Surfire plugin ? 

Thanks by advance. 

Manu

2012/5/2 Peter Niederwieser <pnie...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.




--
Emmanuel DEMEY
Ingénieur Etude et Développement
ATOS Worldline
+33 (0)6 47 47 42 02
demey.e...@gmail.com

Twitter : @gillespie59

Peter Niederwieser

unread,
May 3, 2012, 11:45:37 AM5/3/12
to spockfr...@googlegroups.com
On May 3, 2012, at 9:57 AM, Emmanuel DEMEY wrote:

> Thanks Peter
>
> It works right now.

Would you mind to share what the problem was?

> But I have an other question.
>
> The tests of my existing project is based on TestNG (using a testng.xml file). but Spock use jUnit ? Am I right ?
>
> How can I mix this 2 testing framework in my pom.xml ? By configuring the Surfire plugin ?

Yes. You'll have to configure Surefire to run both TestNG and JUnit tests.

Cheers,
Peter

Emmanuel DEMEY

unread,
May 4, 2012, 11:18:28 AM5/4/12
to spockfr...@googlegroups.com
Yes, Sorry. The problem was the Groovy nature.

Just for the other users, I share my Surfire configuration, that's working !! :

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<testNGArtifactName>none:none</testNGArtifactName>
</configuration>
<executions>
<execution>
<id>TestNG Tests</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<junitArtifactName>none:none</junitArtifactName>
<testNGArtifactName>org.testng:testng</testNGArtifactName>
<suiteXmlFiles>
<suiteXmlFile>target/test-classes/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<excludes>
<exclude>**/*.groovy</exclude>
</excludes>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>


Tanks Peter

2012/5/3 Peter Niederwieser <pnie...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.

Reply all
Reply to author
Forward
0 new messages